|
18 | 18 | description: "Publish to forge.puppet.com" |
19 | 19 | type: boolean |
20 | 20 | default: true |
| 21 | + edit: |
| 22 | + description: "Re-tag and regenerate release notes" |
| 23 | + type: boolean |
| 24 | + default: false |
21 | 25 |
|
22 | 26 | env: |
23 | 27 | FORGE_API_KEY: ${{ secrets.FORGE_API_KEY }} |
| 28 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 29 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
24 | 30 |
|
25 | 31 | jobs: |
26 | 32 | check: |
@@ -50,55 +56,73 @@ jobs: |
50 | 56 |
|
51 | 57 | - name: "Checkout tag ${{ inputs.tag }}" |
52 | 58 | if: ${{ inputs.tag != '' }} |
53 | | - id: checkout |
54 | 59 | run: | |
55 | 60 | git checkout refs/tags/${{ inputs.tag }} |
56 | | - echo "tag=${{ inputs.tag }}" >> $GITHUB_OUTPUT |
57 | 61 |
|
58 | | - - name: "Get metadata version" |
59 | | - id: "get_version" |
| 62 | + - name: "Get metadata" |
| 63 | + id: metadata |
60 | 64 | run: | |
61 | 65 | metadata_version=$(jq --raw-output .version metadata.json) |
62 | 66 | if [[ -n "${{ inputs.tag }}" ]] ; then |
63 | | - tag=${{ steps.checkout.outputs.tag }} |
| 67 | + tag=${{ inputs.tag }} |
64 | 68 | if [[ "${metadata_version}" != "${tag/v}" ]] ; then |
65 | 69 | echo "::error::tag ${tag/v} does not match metadata version ${metadata_version}" |
66 | 70 | exit 1 |
67 | 71 | fi |
| 72 | + else |
| 73 | + tag="v${metadata_version}" |
68 | 74 | fi |
| 75 | + echo "tag=${tag}" >> $GITHUB_OUTPUT |
69 | 76 | echo "version=${metadata_version}" >> $GITHUB_OUTPUT |
70 | 77 |
|
71 | | - - name: "PDK build ${{ steps.get_version.outputs.version }}" |
| 78 | + - name: "PDK build ${{ steps.metadata.outputs.version }}" |
72 | 79 | uses: "docker://puppet/pdk:3.0.0.0" |
73 | 80 | with: |
74 | 81 | args: "build" |
75 | 82 |
|
76 | 83 | - name: "Generate release notes for Github" |
77 | | - if: ${{ inputs.release == true || inputs.release == 'true' }} |
| 84 | + continue-on-error: true |
78 | 85 | run: | |
79 | 86 | export GH_HOST=github.com |
80 | 87 | gh extension install chelnak/gh-changelog |
81 | 88 | gh changelog get --latest | sed -e "1,/^\[Full Changelog\]/ d" > OUTPUT.md |
82 | 89 | echo "::group::release notes" |
83 | 90 | cat OUTPUT.md |
84 | 91 | echo "::endgroup::" |
85 | | - env: |
86 | | - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
87 | 92 |
|
88 | | - - name: "Create release for v${{ steps.get_version.outputs.version }}" |
89 | | - if: ${{ inputs.release == true || inputs.release == 'true' }} |
| 93 | + - name: "Tag ${{ steps.metadata.outputs.tag }}" |
| 94 | + id: tag |
90 | 95 | run: | |
91 | | - if [[ -z "${{ inputs.tag }}" ]] ; then |
92 | | - # create an annotated tag -- gh release create DOES NOT do this for us! |
93 | | - # TODO move this to an automatic action when a release_prep PR is merged |
94 | | - git config --local user.email "${{ github.repository_owner }}@users.noreply.github.com" |
95 | | - git config --local user.name "GitHub Actions" |
96 | | - git tag -a -m "v${{ steps.get_version.outputs.version }}" "v${{ steps.get_version.outputs.version }}" |
97 | | - git push origin tag "v${{ steps.get_version.outputs.version }}" |
| 96 | + # create an annotated tag -- gh release create DOES NOT do this for us! |
| 97 | + # TODO move this to an automatic action when a release_prep PR is merged |
| 98 | + git config --local user.email "${{ github.repository_owner }}@users.noreply.github.com" |
| 99 | + git config --local user.name "GitHub Actions" |
| 100 | +
|
| 101 | + # overwrite existing tag? |
| 102 | + if [[ -n "${{ inputs.tag }}" ]] ; then |
| 103 | + if [[ "${{ inputs.edit }}" == "true" ]] ; then |
| 104 | + arg="-f" |
| 105 | + else |
| 106 | + skip_tag=1 |
| 107 | + fi |
| 108 | + fi |
| 109 | +
|
| 110 | + if [[ -z "${skip_tag}" ]] ; then |
| 111 | + git tag -a $arg -F OUTPUT.md "${{ steps.metadata.outputs.tag }}" |
| 112 | + git push $arg origin tag "${{ steps.metadata.outputs.tag }}" |
| 113 | + fi |
| 114 | +
|
| 115 | + if gh release view "${{ steps.metadata.outputs.tag }}" > /dev/null ; then |
| 116 | + echo "release_action=edit" >> $GITHUB_OUTPUT |
| 117 | + echo "undraft=${{ inputs.edit }}" >> $GITHUB_OUTPUT |
| 118 | + else |
| 119 | + echo "release_action=create" >> $GITHUB_OUTPUT |
98 | 120 | fi |
99 | | - gh release create v${{ steps.get_version.outputs.version }} --title v${{ steps.get_version.outputs.version }} -F OUTPUT.md |
100 | | - env: |
101 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 121 | +
|
| 122 | + - name: "${{ steps.tag.outputs.release_action }} release for ${{ steps.metadata.outputs.tag }}" |
| 123 | + if: ${{ inputs.release == true || inputs.release == 'true' || steps.tag.outputs.undraft == 'true' }} |
| 124 | + run: | |
| 125 | + gh release ${{ steps.tag.outputs.release_action }} ${{ steps.metadata.outputs.tag }} --draft=false --title ${{ steps.metadata.outputs.tag }} -F OUTPUT.md |
102 | 126 |
|
103 | 127 | - name: "Publish module" |
104 | 128 | if: ${{ inputs.publish == true || inputs.publish == 'true' }} |
|
0 commit comments