Skip to content

Commit

Permalink
Merge pull request #97 from puppetlabs/malikparvez-patch-1
Browse files Browse the repository at this point in the history
CAT-1918 : Update module_release.yml
  • Loading branch information
gavindidrichsen authored Jun 14, 2024
2 parents 9cdd6b4 + c5b04c1 commit 25a7fb2
Showing 1 changed file with 18 additions and 110 deletions.
128 changes: 18 additions & 110 deletions .github/workflows/module_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
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'

0 comments on commit 25a7fb2

Please sign in to comment.