Repository navigation
147 lines (123 loc) · 5.63 KB
/
Copy pathdeploy-push.yml
File metadata and controls
147 lines (123 loc) · 5.63 KB
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# 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]
permissions:
contents: read
actions: write
# 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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Setup PHP
uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # v2.37.2
with:
php-version: 8.5
# The slides importer's phpoffice packages need zip and gd
extensions: zip, gd
- name: Get Composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> "$GITHUB_OUTPUT"
- name: Cache Composer dependencies
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
# Composer runs on the runner, not in a container, so the plugin installs
# in install-ssp get the PHP extensions above, npm and a git checkout the
# runner owns
- name: Install dependencies
run: composer install --no-interaction --no-progress --prefer-dist
- 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@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
token: ${{ secrets.ADMIN_GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: 24
- 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@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
github-token: ${{ secrets.ADMIN_GITHUB_TOKEN }}
script: |-
const branch = '${{ github.ref }}'.replace('refs/heads/', '');
await github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: '${{ env.WORKFLOW_ID }}',
ref: branch,
inputs: {
destinationEnvironment: branch === 'main' ? 'production' : 'staging',
},
headers: {
'X-GitHub-Api-Version': '2026-03-10',
},
})
.catch(error => error)
.then(response => {
core.debug(response);
if (response.status !== 200) {
core.setFailed(`createWorkflowDispatch to ${{ env.WORKFLOW_ID }} received status code ${response.status}`)
}
})