-
Notifications
You must be signed in to change notification settings - Fork 15
136 lines (132 loc) · 4.69 KB
/
static.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
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@8e5e7e5ab8b370d6c329ec480221332ada57f0ab
- name: Setup Ruby
uses: ruby/setup-ruby@7d546f4868fb108ed378764d873683f920672ae2
with:
ruby-version: '.ruby-version'
bundler-cache: true
- name: Setup Node
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Setup Pages
uses: actions/configure-pages@f156874f8191504dae5b037505266ed5dda6c382
- 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@d7906e4ad0b1822421a7e6a35d5ca353c962f410
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@d7906e4ad0b1822421a7e6a35d5ca353c962f410
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@0b7f8abb1508181956e8e162db84b466c27e18ce
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@af48cf94a42f2c634308b1c9dc0151830b6f190a