-
Notifications
You must be signed in to change notification settings - Fork 1
130 lines (108 loc) · 4.7 KB
/
deploy-push.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# This workflow deploys the CBF WordPress application on a successful push or PR
name: CI
# Controls when the action will run. Triggers the workflow on push or pull request events
on:
push:
branches: [ develop, main ]
pull_request:
branches: [ develop, main ]
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
setup:
if: ${{ !contains(github.event.head_commit.message, 'chore(release)') }}
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
- name: Install dependencies
uses: php-actions/composer@v6
- name: Install phpcs
run: vendor/bin/phpcs -i
- name: PHP Code Style (phpcs)
run: composer lint:all
version:
if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' && !contains(github.event.head_commit.author.name, 'GitHub Action') }}
needs: [ setup ]
runs-on: ubuntu-latest
outputs:
executed: ${{ steps.tag_release.outputs.executed }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
token: ${{ secrets.ADMIN_GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Install GitHub CLI
run: |
type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y)
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt update \
&& sudo apt install gh -y
- name: Create release branch and pull request
id: tag_release
env:
GH_TOKEN: ${{ secrets.ADMIN_GITHUB_TOKEN }}
run: |
git fetch --unshallow --tags
git config --global user.email "${{github.event.pusher.email}}"
git config --global user.name "${{github.event.pusher.name}}"
# Create a new branch for the release
git checkout -b release-$(date +'%Y%m%d%H%M%S')
# Run version bump and changelog update
npx --yes commit-and-tag-version
# Get the new version
new_version=$(git describe --tags --abbrev=0)
# Push the new branch and tag
git push --set-upstream origin HEAD
git push origin $new_version
# Create a pull request
gh pr create --title "Release $new_version" --body "This PR contains version bump and changelog updates for release $new_version" --base develop
echo 'executed=true' >> $GITHUB_OUTPUT
deploy:
# Ensure execution for stage deployments, as dependent version job is skipped
if: ${{ github.event_name == 'push' && !failure() && (success() || !needs.version.outputs.executed) }}
needs: [ setup, version ]
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Triggers release generation
- name: Deploy to hosting environment
env:
WORKFLOW_ID: ${{ 'deploy-application.yml' }}
uses: actions/github-script@v7
with:
script: |-
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: '${{ env.WORKFLOW_ID }}',
ref: '${{ github.ref }}',
inputs: {
destinationEnvironment: '${{github.ref}}' === 'refs/heads/main' ? 'production' : 'staging',
sourceBranch: '${{ github.ref }}',
},
})
.catch(error => error)
.then(response => {
core.debug(response);
if (response.status !== 204) {
core.setFailed(`createWorkflowDispatch to ${{ env.WORKFLOW_ID }} received status code ${response.status}`)
}
})