Skip to content

Merge pull request #8 from alphagov/pp-12343/change-release-tag-name #12

Merge pull request #8 from alphagov/pp-12343/change-release-tag-name

Merge pull request #8 from alphagov/pp-12343/change-release-tag-name #12

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)
MODULE_NAME=$(./pkl eval -f json src/PklProject | jq -r .package.name)
if [ -z "${MODULE_VERSION:-}" ] || [ -z "${MODULE_NAME:-}" ]; then
echo "Couldn't read module version or name!"
exit 1
fi
echo "MODULE_VERSION=${MODULE_VERSION}" | tee -a "$GITHUB_OUTPUT"
echo "MODULE_TAG=${MODULE_NAME}@${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 }}"
MODULE_TAG: "${{ steps.load-module-version.outputs.MODULE_TAG }}"
with:
script: |
const module_version = process.env.MODULE_VERSION;
const module_tag = process.env.MODULE_TAG;
console.log(`Checking for a release of version ${module_version} with tag ${module_tag}`)
try {
const release = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: module_tag,
})
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_TAG: "${{ steps.load-module-version.outputs.MODULE_TAG }}"
GH_TOKEN: "${{ github.token }}"
run: |
echo "Creating release ${MODULE_TAG}"
gh release create --generate-notes --latest "${MODULE_TAG}" build/*