Skip to content

Merge pull request #778 from alphagov/alanmaddrell-patch-6 #164

Merge pull request #778 from alphagov/alanmaddrell-patch-6

Merge pull request #778 from alphagov/alanmaddrell-patch-6 #164

Workflow file for this run

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