-
Notifications
You must be signed in to change notification settings - Fork 15
136 lines (132 loc) · 4.76 KB
/
static.yml
File metadata and controls
136 lines (132 loc) · 4.76 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
name: Static
on:
push:
branches:
- 'main'
workflow_dispatch:
permissions:
contents: write
pages: write
id-token: write
concurrency:
group: 'pages'
cancel-in-progress: true
jobs:
run-tests:
name: Unit tests and static build
uses: ./.github/workflows/_run-tests.yml
static:
name: Deploy and release Pay product pages
needs: run-tests
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup Ruby
uses: ruby/setup-ruby@97ecb7b512899eb71ab1bf2310a624c6f1589ac6 # 1.308.1
with:
ruby-version: '.ruby-version'
bundler-cache: true
- name: Setup Node
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Setup Pages
uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0
- name: Get Package version
id: get-package-version
run: |
echo "package_version=$(cat package.json | jq -r '.version')" >> $GITHUB_OUTPUT
- name: Get latest release version
id: get-latest-release-version
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
result-encoding: string
script: |
try {
const getReleaseResp = await github.rest.repos.getLatestRelease({
owner: context.repo.owner,
repo: context.repo.repo
})
return getReleaseResp.data.name
} catch(err) {
if (err.name == 'HttpError') {
console.warn("Found HttpError")
if (err.status == 404) {
console.log("No previous GitHub Releases found. Defaulting to 0.0.0")
return "0.0.0"
}
} else {
console.error(`Failed to get the latest release: ${err.message}`)
throw err
}
}
- name: Next release version
id: next-version
uses: alphagov/pay-ci/actions/next-semver@master
with:
package_version: ${{ steps.get-package-version.outputs.package_version }}
release_version: ${{ steps.get-latest-release-version.outputs.result }}
- name: Install and Build
run: |
npm ci
bundle exec middleman build
cat <<EOF > ./build/package.json
{
"name": "pay-product-page",
"version": "${{ steps.next-version.outputs.version }}"
}
EOF
- name: Set artifact name
id: set-artifact-name
run: echo "name=pay-product-page-${{ steps.next-version.outputs.version }}" >> $GITHUB_OUTPUT
- name: Prepare archive for upload
id: archive-assets
shell: sh
run: |
chmod -c -R +rX "build"
tar \
--dereference --hard-dereference \
--directory "build" \
-cvf "${{ steps.set-artifact-name.outputs.name }}.tar" \
.
- name: Create Release
id: create-release
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
var fs = require('fs')
try {
const releaseResponse = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: "${{ steps.next-version.outputs.version }}",
name: "${{ steps.next-version.outputs.version }}"
})
const fileName = "${{ steps.set-artifact-name.outputs.name }}.tar"
const releaseUploadResponse = await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: releaseResponse.data.id,
name: fileName,
data: fs.readFileSync(fileName)
})
} catch(err) {
console.error(`Failed to create release: ${err.message}`)
throw err
}
- name: Upload Pages artifact
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: 'github-pages'
path: ${{ steps.set-artifact-name.outputs.name }}.tar
retention-days: 7
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@cd2ce8fcbc39b97be8ca5fce6e763baed58fa128 # v5.0.0