-
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@0ad4b8fadaa221de15dcec353f45205ec38ea70b
- name: Setup Ruby
uses: ruby/setup-ruby@7bae1d00b5db9166f4f0fc47985a3a5702cb58f0
with:
ruby-version: '.ruby-version'
bundler-cache: true
- name: Setup Node
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8
with:
node-version-file: '.nvmrc'
cache: 'npm'
- name: Setup Pages
uses: actions/configure-pages@983d7736d9b0ae728b81ab479565c72886d7745b
- 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@60a0d83039c74a4aee543508d2ffcb1c3799cdea
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@60a0d83039c74a4aee543508d2ffcb1c3799cdea
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@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
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@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e