Skip to content

Commit 4a177ca

Browse files
committed
support re-tagging and releasing old versions
the previous commit fixed tagging releases with light tags this commit supports re-tagging the old releases, and creating releases for tags that dont have releases.
1 parent de3dd6b commit 4a177ca

File tree

1 file changed

+45
-21
lines changed

1 file changed

+45
-21
lines changed

.github/workflows/module_release.yml

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@ on:
1717
description: "Publish to forge.puppet.com"
1818
type: boolean
1919
default: true
20+
edit:
21+
description: "Re-tag and regenerate release notes"
22+
type: boolean
23+
default: false
2024

2125
env:
2226
FORGE_API_KEY: ${{ secrets.FORGE_API_KEY }}
27+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2329

2430
jobs:
2531
check:
@@ -49,55 +55,73 @@ jobs:
4955

5056
- name: "Checkout tag ${{ inputs.tag }}"
5157
if: ${{ inputs.tag != '' }}
52-
id: checkout
5358
run: |
5459
git checkout refs/tags/${{ inputs.tag }}
55-
echo "tag=${{ inputs.tag }}" >> $GITHUB_OUTPUT
5660
57-
- name: "Get metadata version"
58-
id: "get_version"
61+
- name: "Get metadata"
62+
id: metadata
5963
run: |
6064
metadata_version=$(jq --raw-output .version metadata.json)
6165
if [[ -n "${{ inputs.tag }}" ]] ; then
62-
tag=${{ steps.checkout.outputs.tag }}
66+
tag=${{ inputs.tag }}
6367
if [[ "${metadata_version}" != "${tag/v}" ]] ; then
6468
echo "::error::tag ${tag/v} does not match metadata version ${metadata_version}"
6569
exit 1
6670
fi
71+
else
72+
tag="v${metadata_version}"
6773
fi
74+
echo "tag=${tag}" >> $GITHUB_OUTPUT
6875
echo "version=${metadata_version}" >> $GITHUB_OUTPUT
6976
70-
- name: "PDK build ${{ steps.get_version.outputs.version }}"
77+
- name: "PDK build ${{ steps.metadata.outputs.version }}"
7178
uses: "docker://puppet/pdk:3.0.0.0"
7279
with:
7380
args: "build"
7481

7582
- name: "Generate release notes for Github"
76-
if: ${{ inputs.release == true || inputs.release == 'true' }}
83+
continue-on-error: true
7784
run: |
7885
export GH_HOST=github.com
7986
gh extension install chelnak/gh-changelog
8087
gh changelog get --latest | sed -e "1,/^\[Full Changelog\]/ d" > OUTPUT.md
8188
echo "::group::release notes"
8289
cat OUTPUT.md
8390
echo "::endgroup::"
84-
env:
85-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8691
87-
- name: "Create release for v${{ steps.get_version.outputs.version }}"
88-
if: ${{ inputs.release == true || inputs.release == 'true' }}
92+
- name: "Tag ${{ steps.metadata.outputs.tag }}"
93+
id: tag
8994
run: |
90-
if [[ -z "${{ inputs.tag }}" ]] ; then
91-
# create an annotated tag -- gh release create DOES NOT do this for us!
92-
# TODO move this to an automatic action when a release_prep PR is merged
93-
git config --local user.email "${{ github.repository_owner }}@users.noreply.github.com"
94-
git config --local user.name "GitHub Actions"
95-
git tag -a -m "v${{ steps.get_version.outputs.version }}" "v${{ steps.get_version.outputs.version }}"
96-
git push origin tag "v${{ steps.get_version.outputs.version }}"
95+
# create an annotated tag -- gh release create DOES NOT do this for us!
96+
# TODO move this to an automatic action when a release_prep PR is merged
97+
git config --local user.email "${{ github.repository_owner }}@users.noreply.github.com"
98+
git config --local user.name "GitHub Actions"
99+
100+
# overwrite existing tag?
101+
if [[ -n "${{ inputs.tag }}" ]] ; then
102+
if [[ "${{ inputs.edit }}" == "true" ]] ; then
103+
arg="-f"
104+
else
105+
skip_tag=1
106+
fi
107+
fi
108+
109+
if [[ -z "${skip_tag}" ]] ; then
110+
git tag -a $arg -F OUTPUT.md "${{ steps.metadata.outputs.tag }}"
111+
git push $arg origin tag "${{ steps.metadata.outputs.tag }}"
112+
fi
113+
114+
if gh release view "${{ steps.metadata.outputs.tag }}" > /dev/null ; then
115+
echo "release_action=edit" >> $GITHUB_OUTPUT
116+
echo "undraft=${{ inputs.edit }}" >> $GITHUB_OUTPUT
117+
else
118+
echo "release_action=create" >> $GITHUB_OUTPUT
97119
fi
98-
gh release create v${{ steps.get_version.outputs.version }} --title v${{ steps.get_version.outputs.version }} -F OUTPUT.md
99-
env:
100-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
120+
121+
- name: "${{ steps.tag.outputs.release_action }} release for ${{ steps.metadata.outputs.tag }}"
122+
if: ${{ inputs.release == true || inputs.release == 'true' || steps.tag.outputs.undraft == 'true' }}
123+
run: |
124+
gh release ${{ steps.tag.outputs.release_action }} ${{ steps.metadata.outputs.tag }} --draft=false --title ${{ steps.metadata.outputs.tag }} -F OUTPUT.md
101125
102126
- name: "Publish module"
103127
if: ${{ inputs.publish == true || inputs.publish == 'true' }}

0 commit comments

Comments
 (0)