Create Tag and Release changelog #52
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_OUTPUT | |
- name: print tag | |
id: print_tag | |
run: | | |
echo "Old Tag: ${{ steps.get_tag.outputs.old_tag_name }}" | |
echo "LATEST_TAG=${{ steps.get_tag.outputs.old_tag_name }}" >> $GITHUB_ENV | |
echo "NEW_TAG=${{ github.event.inputs.tag_name }}" >> $GITHUB_ENV | |
echo "Old event: ${{ github.event }}" | |
echo "Old github: ${{ toJson(github) }}" | |
echo "Old job: ${{ toJson(job) }}" | |
echo "Old steps:${{ toJson(steps) }} | |
- name: Check if new tag already exists | |
id: check_tag | |
run: | | |
if git rev-parse ${{ github.event.inputs.tag_name }} >/dev/null 2>&1; then | |
echo "Error: Tag '${{ github.event.inputs.tag_name }}' already exists." | |
exit 1 | |
fi | |
continue-on-error: false | |
shell: bash | |
- name: Handle Failure | |
if: failure() | |
run: | | |
echo "Tag already exists. Workflow failed." | |
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 | |
with: | |
ref: ${{ needs.fetch-tag.outputs.old_tag }} | |
- 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 "prepare for release and update params" | |
git tag -a -m "Tag for release: ${{ github.event.inputs.tag_name }}" ${{ github.event.inputs.tag_name }} | |
git push origin ${{ github.event.inputs.tag_name }} | |
changelog: | |
name: Build Changelog | |
needs: [update-params-env,fetch-tag] | |
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@v2 | |
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 }} | |