Create Tag and Release changelog #39
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Create Tag and Release changelog | |
on: | |
workflow_dispatch: | |
inputs: | |
tag_name: | |
description: 'Tag name for the new release' | |
required: true | |
permissions: | |
contents: write | |
packages: write | |
pull-requests: write | |
jobs: | |
fetch-tag: | |
runs-on: ubuntu-latest | |
outputs: | |
old_tag: ${{ steps.get_tag.outputs.old_tag_name }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Get latest tag | |
id: get_tag | |
run: | | |
echo "old_tag_name=$(git ls-remote --tags origin | awk -F"/" '{print $3}' | grep -v '{}' | sort -V | tail -n1)" >> $GITHUB_ENV | |
echo "${old_tag_name}" | |
- name: print tag | |
id: print_tag | |
run: | | |
echo "Old Tag: ${{ steps.get_tag.outputs.old_tag_name }}" | |
- name: Compare tags | |
id: compare_tags | |
run: | | |
run: | | |
latest_tag=${{ steps.get_tag.outputs.old_tag_name }} | |
new_tag=v0.0.2 | |
echo "Latest Tag: $latest_tag" | |
echo "New Tag: $new_tag" | |
node -e "const latestMajor = parseInt(process.env.LATEST_TAG.substring(1).split('.')[0]); const latestMinor = parseInt(process.env.LATEST_TAG.substring(1).split('.')[1]); const latestPatch = parseInt(process.env.LATEST_TAG.substring(1).split('.')[2]); const newMajor = parseInt(process.env.NEW_TAG.substring(1).split('.')[0]); const newMinor = parseInt(process.env.NEW_TAG.substring(1).split('.')[1]); const newPatch = parseInt(process.env.NEW_TAG.substring(1).split('.')[2]); if (latestMajor > newMajor || (latestMajor === newMajor && latestMinor > newMinor) || (latestMajor === newMajor && latestMinor === newMinor && latestPatch >= newPatch)) { console.log('Error: New tag is not greater than the latest tag.'); process.exit(1); }" | |
update-params-env: | |
runs-on: ubuntu-latest | |
needs: fetch-tag | |
outputs: | |
param_env: ${{ steps.read_params_env.outputs.params_env }} | |
# release_version: ${{ steps.get_release_version.outputs.release_version }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Read params.env | |
id: read_params_env | |
run: | | |
echo "params_env=$(cat config/params.env)" >> $GITHUB_OUTPUT | |
# - name: Read release version | |
# id: get_release_version | |
# run: echo "release_version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT | |
- name: Update params.env with new release version | |
run: | | |
sed -i 's|:v[0-9.]*\b|:${{ github.event.inputs.tag_name }}|gm' config/params.env | |
- name: Commit changes | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "GitHub Actions" | |
git add config/params.env | |
git commit -m "Update params.env with new release tags [$${{ github.event.inputs.tag_name }}]" | |
git push | |
changelog: | |
name: Build Changelog | |
needs: update-params-env | |
runs-on: ubuntu-latest | |
outputs: | |
changelog: ${{ steps.build_changelog.outputs.changelog }} | |
env: | |
old_tag: ${{ needs.fetch-tag.outputs.old_tag }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: changelog print old tag | |
run: echo "old_tag is $old_tag" | |
- name: Build Changelog | |
id: build_changelog | |
uses: mikepenz/release-changelog-builder-action@v4 | |
with: | |
fromTag: ${{ needs.fetch-tag.outputs.old_tag }} | |
toTag: ${{ github.event.inputs.tag_name }} | |
token: ${{ github.TOKEN }} | |
- name: print_output | |
run: echo "${{ toJson(steps.build_changelog.outputs) }}" | |
release: | |
name: Release | |
needs: [changelog,fetch-tag] | |
runs-on: ubuntu-latest | |
env: | |
changelog: ${{ needs.changelog.outputs.changelog }} | |
old_tag: ${{ needs.fetch-tag.outputs.old_tag }} | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Generate Release Notes | |
run: echo ${{ env.changelog }} | |
- name: Create Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
token: ${{ github.TOKEN }} | |
tag_name: ${{ github.event.inputs.tag_name }} | |
prerelease: false | |
draft: false | |
files: bin/* | |
generate_release_notes: true | |
name: ${{ github.event.inputs.tag_name }} | |
# body: | | |
# ## What's Changed | |
# ### abcd/ABCD | |
# https://github.com/Kaustubh-pande/scaffolding-microservice/releases/tags/${{ env.old_tag }} | |
# ### xyz/XYZ | |
# ${{ needs.changelog.outputs.changelog }} | |