Skip to content

Commit 25a7fb2

Browse files
Merge pull request #97 from puppetlabs/malikparvez-patch-1
CAT-1918 : Update module_release.yml
2 parents 9cdd6b4 + c5b04c1 commit 25a7fb2

File tree

1 file changed

+18
-110
lines changed

1 file changed

+18
-110
lines changed

.github/workflows/module_release.yml

+18-110
Original file line numberDiff line numberDiff line change
@@ -5,139 +5,47 @@ 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-
default: ''
12-
type: string
13-
release:
14-
description: "Create a release on Github"
15-
type: boolean
16-
default: true
17-
publish:
18-
description: "Publish to forge.puppet.com"
19-
type: boolean
20-
default: true
21-
edit:
22-
description: "Re-tag and regenerate release notes"
23-
type: boolean
24-
default: false
25-
26-
env:
27-
FORGE_API_KEY: ${{ secrets.FORGE_API_KEY }}
28-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
308

319
jobs:
32-
check:
33-
runs-on: "ubuntu-latest"
34-
steps:
35-
- name: "Check Requirements"
36-
if: ${{ inputs.publish == true || inputs.publish == 'true' }}
37-
run: |
38-
if [[ -z "${FORGE_API_KEY}" ]] ; then
39-
echo "::error::missing required secret: FORGE_API_KEY"
40-
exit 1
41-
fi
42-
4310
release:
44-
name: ${{ inputs.tag != '' && inputs.tag || 'new' }}
45-
needs: check
11+
name: "Release"
4612
runs-on: "ubuntu-latest"
13+
if: github.repository_owner == 'puppetlabs'
4714

4815
steps:
16+
4917
- name: "Checkout"
5018
uses: "actions/checkout@v4"
5119
with:
5220
ref: "${{ github.ref }}"
5321
clean: true
5422
fetch-depth: 0
55-
fetch-tags: true
56-
57-
- name: "Checkout tag ${{ inputs.tag }}"
58-
if: ${{ inputs.tag != '' }}
59-
run: |
60-
git checkout refs/tags/${{ inputs.tag }}
6123

62-
- name: "Get metadata"
63-
id: metadata
24+
- name: "Get version"
25+
id: "get_version"
6426
run: |
65-
metadata_version=$(jq --raw-output .version metadata.json)
66-
if [[ -n "${{ inputs.tag }}" ]] ; then
67-
tag=${{ inputs.tag }}
68-
if [[ "${metadata_version}" != "${tag/v}" ]] ; then
69-
echo "::error::tag ${tag/v} does not match metadata version ${metadata_version}"
70-
exit 1
71-
fi
72-
else
73-
tag="v${metadata_version}"
74-
fi
75-
echo "tag=${tag}" >> $GITHUB_OUTPUT
76-
echo "version=${metadata_version}" >> $GITHUB_OUTPUT
27+
echo "version=$(jq --raw-output .version metadata.json)" >> $GITHUB_OUTPUT
7728
78-
- name: "PDK build ${{ steps.metadata.outputs.version }}"
79-
uses: "docker://puppet/pdk:3.0.0.0"
29+
- name: "PDK build"
30+
uses: "docker://puppet/pdk:nightly"
8031
with:
8132
args: "build"
8233

83-
- name: "Generate release notes for Github"
84-
continue-on-error: true
34+
- name: "Generate release notes"
8535
run: |
8636
export GH_HOST=github.com
8737
gh extension install chelnak/gh-changelog
88-
# TODO replace sed when gh-changelog supports templates
89-
gh changelog get --latest | \
90-
sed -e "1,/^\[Full Changelog\]/ d" \
91-
-e 's/(\[\([^]]*\)\]([^)]*))$/@\1/g' \
92-
-e 's/\[#\([0-9]*\)\]([^)]*)/#\1/g' > OUTPUT.md
93-
echo "::group::release notes"
94-
cat OUTPUT.md
95-
echo "::endgroup::"
96-
97-
- name: "Tag ${{ steps.metadata.outputs.tag }}"
98-
id: tag
99-
run: |
100-
# create an annotated tag -- gh release create DOES NOT do this for us!
101-
# TODO move this to an automatic action when a release_prep PR is merged
102-
git config --local user.email "${{ github.repository_owner }}@users.noreply.github.com"
103-
git config --local user.name "GitHub Actions"
104-
105-
# overwrite existing tag?
106-
if [[ -n "${{ inputs.tag }}" ]] ; then
107-
if [[ "${{ inputs.edit }}" == "true" ]] ; then
108-
arg="-f"
109-
else
110-
skip_tag=1
111-
fi
112-
fi
113-
114-
if [[ -z "${skip_tag}" ]] ; then
115-
GIT_COMMITTER_DATE="$(git log --format=%aD ...HEAD^)" git tag -a $arg -F OUTPUT.md "${{ steps.metadata.outputs.tag }}"
116-
git push $arg origin tag "${{ steps.metadata.outputs.tag }}"
117-
fi
118-
119-
if gh release view "${{ steps.metadata.outputs.tag }}" > /dev/null ; then
120-
echo "release_action=edit" >> $GITHUB_OUTPUT
121-
echo "undraft=${{ inputs.edit }}" >> $GITHUB_OUTPUT
122-
else
123-
echo "release_action=create" >> $GITHUB_OUTPUT
124-
fi
125-
126-
# is latest tag?
127-
LAST_TAG=$(git for-each-ref refs/tags --sort='-*creatordate' --format='%(refname:short)' --count=1)
128-
if [[ "${LAST_TAG}" == "${{ steps.metadata.outputs.tag }}" ]] ; then
129-
echo "latest=true" >> $GITHUB_OUTPUT
130-
else
131-
echo "latest=false" >> $GITHUB_OUTPUT
132-
fi
38+
gh changelog get --latest > OUTPUT.md
39+
env:
40+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13341

134-
- name: "${{ steps.tag.outputs.release_action }} release for ${{ steps.metadata.outputs.tag }}"
135-
if: ${{ inputs.release == true || inputs.release == 'true' || steps.tag.outputs.undraft == 'true' }}
42+
- name: "Create release"
13643
run: |
137-
gh release ${{ steps.tag.outputs.release_action }} ${{ steps.metadata.outputs.tag }} --latest=${{ steps.tag.outputs.latest }} --draft=false --title ${{ steps.metadata.outputs.tag }} -F OUTPUT.md
44+
gh release create v${{ steps.get_version.outputs.version }} --title v${{ steps.get_version.outputs.version }} -F OUTPUT.md
45+
env:
46+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13847

13948
- name: "Publish module"
140-
if: ${{ inputs.publish == true || inputs.publish == 'true' }}
141-
uses: "docker://puppet/pdk:3.0.0.0"
49+
uses: "docker://puppet/pdk:nightly"
14250
with:
143-
args: 'release publish --forge-token ${{ env.FORGE_API_KEY }} --force'
51+
args: 'release publish --forge-token ${{ secrets.FORGE_API_KEY }} --force'

0 commit comments

Comments
 (0)