add support for releasing any tag #1
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a generic workflow for releasing a Puppet module. | ||
# It requires that the caller sets `secrets: inherit` to ensure | ||
# that secrets are visible from steps in this workflow. | ||
name: "Module Release" | ||
on: | ||
workflow_call: | ||
inputs: | ||
tag: | ||
description: Tag to release (default: latest tag on branch) | ||
type: string | ||
test: | ||
description: Skip publish steps | ||
type: boolean | ||
jobs: | ||
release: | ||
name: "Release" | ||
runs-on: "ubuntu-latest" | ||
steps: | ||
- name: "Check Requirements" | ||
run: | | ||
if [[ -z "${{ secrets.FORGE_API_KEY }}" ]] ; then | ||
echo "::error::missing required secret: FORGE_API_KEY" | ||
exit 1 | ||
fi | ||
- name: "Checkout" | ||
uses: "actions/checkout@v4" | ||
with: | ||
ref: "${{ github.ref }}" | ||
clean: true | ||
fetch-depth: 1 | ||
fetch-tags: true | ||
- name: "Switch HEAD to release" | ||
id: switch | ||
run: | | ||
if [[ -n "${{ inputs.tag }}" ]] ; then | ||
git checkout refs/tags/${{ inputs.tag }} | ||
echo "tag=${{ inputs.tag }}" >> $GITHUB_OUTPUT | ||
else | ||
if TAG=$(git for-each-ref refs/tags --sort=-taggerdate --format='%(refname:sort)' --count=1 --merged=HEAD) ; then | ||
git checkout refs/tags/${TAG} | ||
echo "tag=${TAG}" >> $GITHUB_OUTPUT | ||
else | ||
echo "::error::failed to find a tag on ref ${{ github.ref }}" | ||
fi | ||
fi | ||
- name: "Get version" | ||
id: "get_version" | ||
run: | | ||
metadata_version=$(jq --raw-output .version metadata.json) | ||
tag=${{ steps.switch.outputs.tag }} | ||
if [[ "${metadata_version}" != "${tag/v}" ]] ; then | ||
echo "::error::tag ${tag/v} does not match metadata version ${metadata_version}" | ||
exit 1 | ||
fi | ||
echo "version=${metadata_version}" >> $GITHUB_OUTPUT | ||
- name: "PDK build" | ||
uses: "docker://puppet/pdk:3.0.0.0" | ||
with: | ||
args: "build" | ||
- name: "Generate release notes" | ||
run: | | ||
export GH_HOST=github.com | ||
gh extension install chelnak/gh-changelog | ||
gh changelog get --latest > OUTPUT.md | ||
echo "::group::release notes" | ||
cat OUTPUT.md | ||
echo "::endgroup::" | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: "Create release for v${{ steps.get_version.outputs.version }}" | ||
if: ${{ inputs.test != true && inputs.test != 'true' }} | ||
run: | | ||
gh release create v${{ steps.get_version.outputs.version }} --title v${{ steps.get_version.outputs.version }} -F OUTPUT.md | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
- name: "Publish module" | ||
if: ${{ inputs.test != true && inputs.test != 'true' }} | ||
uses: "docker://puppet/pdk:3.0.0.0" | ||
with: | ||
args: 'release publish --forge-token ${{ secrets.FORGE_API_KEY }} --force' |