Skip to content

Merge pull request #3 from alphagov/pp-12343/add-post-merge-package-a… #8

Merge pull request #3 from alphagov/pp-12343/add-post-merge-package-a…

Merge pull request #3 from alphagov/pp-12343/add-post-merge-package-a… #8

Workflow file for this run

name: Post Merge
on:
push:
branches:
- main
permissions:
contents: read
jobs:
tests:
uses: ./.github/workflows/run-tests.yml
release-package:
needs: tests
runs-on: ubuntu-latest
permissions:
contents: write
name: Check for, and perform release
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
fetch-depth: '0'
- name: Load pkl version
id: load-pkl-version
run: |
PKL_VERSION=$(cat .pkl-version)
echo "PKL_VERSION=${PKL_VERSION}" | tee -a "$GITHUB_OUTPUT"
- name: Install pkl
env:
PKL_VERSION: "${{ steps.load-pkl-version.outputs.PKL_VERSION }}"
run: |
curl -L -o pkl https://github.com/apple/pkl/releases/download/${PKL_VERSION}/pkl-linux-amd64
chmod u+x pkl
./pkl --version
- name: Get pkl module version
id: load-module-version
run: |
set -o pipefail
MODULE_VERSION=$(./pkl eval -f json src/PklProject | jq -r .package.version)
if [ -z "${MODULE_VERSION:-}" ]; then
echo "Couldn't read module version!"
exit 1
fi
echo "MODULE_VERSION=${MODULE_VERSION}" | tee -a "$GITHUB_OUTPUT"
- name: Check for existing release
id: check-for-existing-release
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea
env:
MODULE_VERSION: "${{ steps.load-module-version.outputs.MODULE_VERSION }}"
with:
script: |
const module_version = process.env.MODULE_VERSION;
console.log(`Checking for a release of version ${module_version}`)
try {
const release = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: module_version,
})
console.log(`Release found for version ${module_version}, no need to do a new release`)
core.setOutput('RELEASE_EXISTS', 'true')
} catch (error) {
if (error.status === 404) {
console.log("No release found, release required")
core.setOutput('RELEASE_EXISTS', 'false')
return
}
throw error
}
- if: steps.check-for-existing-release.outputs.RELEASE_EXISTS == 'false'
name: Build new version
run: |
./pkl project package src/ --output-path build/
- if: steps.check-for-existing-release.outputs.RELEASE_EXISTS == 'false'
name: Release new version
env:
MODULE_VERSION: "${{ steps.load-module-version.outputs.MODULE_VERSION }}"
run: |
echo "Creating release ${MODULE_VERSION}"
gh release create --create-notes --latest "${MODULE_VERSION}" build/*