@@ -5,47 +5,139 @@ name: "Module Release"
55
66on :
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 }}
830
931jobs :
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+
1043 release :
11- name : " Release"
44+ name : ${{ inputs.tag != '' && inputs.tag || 'new' }}
45+ needs : check
1246 runs-on : " ubuntu-latest"
13- if : github.repository_owner == 'puppetlabs'
1447
1548 steps :
16-
1749 - name : " Checkout"
1850 uses : " actions/checkout@v4"
1951 with :
2052 ref : " ${{ github.ref }}"
2153 clean : true
2254 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 }}
2361
24- - name : " Get version "
25- id : " get_version "
62+ - name : " Get metadata "
63+ id : metadata
2664 run : |
27- echo "version=$(jq --raw-output .version metadata.json)" >> $GITHUB_OUTPUT
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
2877
29- - name : " PDK build"
78+ - name : " PDK build ${{ steps.metadata.outputs.version }} "
3079 uses : " docker://puppet/pdk:3.0.0.0"
3180 with :
3281 args : " build"
3382
34- - name : " Generate release notes"
83+ - name : " Generate release notes for Github"
84+ continue-on-error : true
3585 run : |
3686 export GH_HOST=github.com
3787 gh extension install chelnak/gh-changelog
38- gh changelog get --latest > OUTPUT.md
39- env :
40- GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
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
41133
42- - name : " Create release"
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' }}
43136 run : |
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 }}
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
47138
48139 - name : " Publish module"
140+ if : ${{ inputs.publish == true || inputs.publish == 'true' }}
49141 uses : " docker://puppet/pdk:3.0.0.0"
50142 with :
51- args : ' release publish --forge-token ${{ secrets .FORGE_API_KEY }} --force'
143+ args : ' release publish --forge-token ${{ env .FORGE_API_KEY }} --force'
0 commit comments