From 429cf3a609386f029f8a7ecb6aef5b2df763e03f Mon Sep 17 00:00:00 2001 From: Malik Parvez <84777619+malikparvez@users.noreply.github.com> Date: Fri, 14 Jun 2024 13:16:41 +0530 Subject: [PATCH 1/2] Update module_release.yml --- .github/workflows/module_release.yml | 130 ++++----------------------- 1 file changed, 19 insertions(+), 111 deletions(-) diff --git a/.github/workflows/module_release.yml b/.github/workflows/module_release.yml index 0879288..0f2a2fd 100644 --- a/.github/workflows/module_release.yml +++ b/.github/workflows/module_release.yml @@ -5,139 +5,47 @@ name: "Module Release" on: workflow_call: - inputs: - tag: - description: "Enter an old tag, or blank to tag HEAD of branch" - default: '' - type: string - release: - description: "Create a release on Github" - type: boolean - default: true - publish: - description: "Publish to forge.puppet.com" - type: boolean - default: true - edit: - description: "Re-tag and regenerate release notes" - type: boolean - default: false - -env: - FORGE_API_KEY: ${{ secrets.FORGE_API_KEY }} - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} jobs: - check: - runs-on: "ubuntu-latest" - steps: - - name: "Check Requirements" - if: ${{ inputs.publish == true || inputs.publish == 'true' }} - run: | - if [[ -z "${FORGE_API_KEY}" ]] ; then - echo "::error::missing required secret: FORGE_API_KEY" - exit 1 - fi - release: - name: ${{ inputs.tag != '' && inputs.tag || 'new' }} - needs: check + name: "Release" runs-on: "ubuntu-latest" + if: github.repository_owner == 'puppetlabs' steps: + - name: "Checkout" - uses: "actions/checkout@v4" + uses: "actions/checkout@v3" with: ref: "${{ github.ref }}" clean: true fetch-depth: 0 - fetch-tags: true - - - name: "Checkout tag ${{ inputs.tag }}" - if: ${{ inputs.tag != '' }} - run: | - git checkout refs/tags/${{ inputs.tag }} - - name: "Get metadata" - id: metadata + - name: "Get version" + id: "get_version" run: | - metadata_version=$(jq --raw-output .version metadata.json) - if [[ -n "${{ inputs.tag }}" ]] ; then - tag=${{ inputs.tag }} - if [[ "${metadata_version}" != "${tag/v}" ]] ; then - echo "::error::tag ${tag/v} does not match metadata version ${metadata_version}" - exit 1 - fi - else - tag="v${metadata_version}" - fi - echo "tag=${tag}" >> $GITHUB_OUTPUT - echo "version=${metadata_version}" >> $GITHUB_OUTPUT + echo "version=$(jq --raw-output .version metadata.json)" >> $GITHUB_OUTPUT - - name: "PDK build ${{ steps.metadata.outputs.version }}" - uses: "docker://puppet/pdk:3.0.0.0" + - name: "PDK build" + uses: "docker://puppet/pdk:nightly" with: args: "build" - - name: "Generate release notes for Github" - continue-on-error: true + - name: "Generate release notes" run: | export GH_HOST=github.com gh extension install chelnak/gh-changelog - # TODO replace sed when gh-changelog supports templates - gh changelog get --latest | \ - sed -e "1,/^\[Full Changelog\]/ d" \ - -e 's/(\[\([^]]*\)\]([^)]*))$/@\1/g' \ - -e 's/\[#\([0-9]*\)\]([^)]*)/#\1/g' > OUTPUT.md - echo "::group::release notes" - cat OUTPUT.md - echo "::endgroup::" - - - name: "Tag ${{ steps.metadata.outputs.tag }}" - id: tag - run: | - # create an annotated tag -- gh release create DOES NOT do this for us! - # TODO move this to an automatic action when a release_prep PR is merged - git config --local user.email "${{ github.repository_owner }}@users.noreply.github.com" - git config --local user.name "GitHub Actions" - - # overwrite existing tag? - if [[ -n "${{ inputs.tag }}" ]] ; then - if [[ "${{ inputs.edit }}" == "true" ]] ; then - arg="-f" - else - skip_tag=1 - fi - fi - - if [[ -z "${skip_tag}" ]] ; then - GIT_COMMITTER_DATE="$(git log --format=%aD ...HEAD^)" git tag -a $arg -F OUTPUT.md "${{ steps.metadata.outputs.tag }}" - git push $arg origin tag "${{ steps.metadata.outputs.tag }}" - fi - - if gh release view "${{ steps.metadata.outputs.tag }}" > /dev/null ; then - echo "release_action=edit" >> $GITHUB_OUTPUT - echo "undraft=${{ inputs.edit }}" >> $GITHUB_OUTPUT - else - echo "release_action=create" >> $GITHUB_OUTPUT - fi - - # is latest tag? - LAST_TAG=$(git for-each-ref refs/tags --sort='-*creatordate' --format='%(refname:short)' --count=1) - if [[ "${LAST_TAG}" == "${{ steps.metadata.outputs.tag }}" ]] ; then - echo "latest=true" >> $GITHUB_OUTPUT - else - echo "latest=false" >> $GITHUB_OUTPUT - fi + gh changelog get --latest > OUTPUT.md + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: "${{ steps.tag.outputs.release_action }} release for ${{ steps.metadata.outputs.tag }}" - if: ${{ inputs.release == true || inputs.release == 'true' || steps.tag.outputs.undraft == 'true' }} + - name: "Create release" run: | - 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 + gh release create v${{ steps.get_version.outputs.version }} --title v${{ steps.get_version.outputs.version }} -F OUTPUT.md + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: "Publish module" - if: ${{ inputs.publish == true || inputs.publish == 'true' }} - uses: "docker://puppet/pdk:3.0.0.0" + uses: "docker://puppet/pdk:nightly" with: - args: 'release publish --forge-token ${{ env.FORGE_API_KEY }} --force' + args: 'release publish --forge-token ${{ secrets.FORGE_API_KEY }} --force' From c5b04c1489d3967e79057216fcef9d9b7fc7c765 Mon Sep 17 00:00:00 2001 From: Malik Parvez <84777619+malikparvez@users.noreply.github.com> Date: Fri, 14 Jun 2024 13:52:07 +0530 Subject: [PATCH 2/2] Update module_release.yml --- .github/workflows/module_release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/module_release.yml b/.github/workflows/module_release.yml index 0f2a2fd..a022e56 100644 --- a/.github/workflows/module_release.yml +++ b/.github/workflows/module_release.yml @@ -15,7 +15,7 @@ jobs: steps: - name: "Checkout" - uses: "actions/checkout@v3" + uses: "actions/checkout@v4" with: ref: "${{ github.ref }}" clean: true