Skip to content

Commit 01dd338

Browse files
committed
support existing tags and make releasing/publishing optional
1 parent 9623061 commit 01dd338

File tree

1 file changed

+52
-10
lines changed

1 file changed

+52
-10
lines changed

.github/workflows/module_release.yml

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,94 @@ name: "Module Release"
55

66
on:
77
workflow_call:
8+
inputs:
9+
tag:
10+
description: "Enter an old tag, or blank to tag HEAD of branch"
11+
type: string
12+
release:
13+
description: "Create a release on Github"
14+
type: boolean
15+
default: true
16+
publish:
17+
description: "Publish to forge.puppet.com"
18+
type: boolean
19+
default: true
20+
21+
env:
22+
FORGE_API_KEY: ${{ secrets.FORGE_API_KEY }}
823

924
jobs:
10-
release:
11-
name: "Release"
25+
check:
1226
runs-on: "ubuntu-latest"
13-
1427
steps:
1528
- name: "Check Requirements"
29+
if: ${{ inputs.publish == true || inputs.publish == 'true' }}
1630
run: |
17-
if [[ -z "${{ secrets.FORGE_API_KEY }}" ]] ; then
31+
if [[ -z "${FORGE_API_KEY}" ]] ; then
1832
echo "::error::missing required secret: FORGE_API_KEY"
1933
exit 1
2034
fi
2135
36+
release:
37+
name: ${{ inputs.tag != '' && inputs.tag || 'new' }}
38+
needs: check
39+
runs-on: "ubuntu-latest"
40+
41+
steps:
2242
- name: "Checkout"
2343
uses: "actions/checkout@v4"
2444
with:
2545
ref: "${{ github.ref }}"
2646
clean: true
2747
fetch-depth: 0
48+
fetch-tags: true
2849

29-
- name: "Get version"
50+
- name: "Checkout tag ${{ inputs.tag }}"
51+
if: ${{ inputs.tag != '' }}
52+
id: checkout
53+
run: |
54+
git checkout refs/tags/${{ inputs.tag }}
55+
echo "tag=${{ inputs.tag }}" >> $GITHUB_OUTPUT
56+
57+
- name: "Get metadata version"
3058
id: "get_version"
3159
run: |
32-
echo "version=$(jq --raw-output .version metadata.json)" >> $GITHUB_OUTPUT
60+
metadata_version=$(jq --raw-output .version metadata.json)
61+
if [[ -n "${{ inputs.tag }}" ]] ; then
62+
tag=${{ steps.checkout.outputs.tag }}
63+
if [[ "${metadata_version}" != "${tag/v}" ]] ; then
64+
echo "::error::tag ${tag/v} does not match metadata version ${metadata_version}"
65+
exit 1
66+
fi
67+
fi
68+
echo "version=${metadata_version}" >> $GITHUB_OUTPUT
3369
34-
- name: "PDK build"
70+
- name: "PDK build ${{ steps.get_version.outputs.version }}"
3571
uses: "docker://puppet/pdk:3.0.0.0"
3672
with:
3773
args: "build"
3874

39-
- name: "Generate release notes"
75+
- name: "Generate release notes for Github"
76+
if: ${{ inputs.release == true || inputs.release == 'true' }}
4077
run: |
4178
export GH_HOST=github.com
4279
gh extension install chelnak/gh-changelog
4380
gh changelog get --latest > OUTPUT.md
81+
echo "::group::release notes"
82+
cat OUTPUT.md
83+
echo "::endgroup::"
4484
env:
4585
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4686

47-
- name: "Create release"
87+
- name: "Create release for v${{ steps.get_version.outputs.version }}"
88+
if: ${{ inputs.release == true || inputs.release == 'true' }}
4889
run: |
4990
gh release create v${{ steps.get_version.outputs.version }} --title v${{ steps.get_version.outputs.version }} -F OUTPUT.md
5091
env:
5192
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5293

5394
- name: "Publish module"
95+
if: ${{ inputs.publish == true || inputs.publish == 'true' }}
5496
uses: "docker://puppet/pdk:3.0.0.0"
5597
with:
56-
args: 'release publish --forge-token ${{ secrets.FORGE_API_KEY }} --force'
98+
args: 'release publish --forge-token ${{ env.FORGE_API_KEY }} --force'

0 commit comments

Comments
 (0)