From 4e4aa5fbd647383bb845594af802a19d60803566 Mon Sep 17 00:00:00 2001 From: rpancham Date: Thu, 18 Apr 2024 17:56:29 +0530 Subject: [PATCH 1/2] Add tag and Release workflow Signed-off-by: rpancham --- .github/workflows/create-tag-release.yml | 82 ++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 .github/workflows/create-tag-release.yml diff --git a/.github/workflows/create-tag-release.yml b/.github/workflows/create-tag-release.yml new file mode 100644 index 00000000..f506f13a --- /dev/null +++ b/.github/workflows/create-tag-release.yml @@ -0,0 +1,82 @@ +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 + with: + ref: ${{ github.ref }} + fetch-depth: 0 + + - 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 "NEW_TAG=${{ github.event.inputs.tag_name }}" >> $GITHUB_ENV + echo "$(basename ${{ github.ref }})" + + - name: Check if tag exists + id: check_tag + run: | + import sys + import subprocess + tag_name = "${{ github.event.inputs.tag_name }}" + command = ['git', 'tag', '-l', tag_name] + output = subprocess.check_output(command, stderr=subprocess.STDOUT) + if output.decode() != "": + print(f"Error: Tag '{tag_name}' already exists.", file=sys.stderr) + sys.exit(1) + else: + print(f"Tag '{tag_name}' does not exists.") + shell: python + continue-on-error: false + + - name: Create Tag + id: create_tag + run: | + git config --global user.email "github-actions@github.com" + git config --global user.name "GitHub Actions" + git tag -a ${{ github.event.inputs.tag_name }} -m "Prepare for ODH release ${{ github.event.inputs.tag_name }}" + git push origin ${{ github.event.inputs.tag_name }} + + changelog: + name: Changelog + needs: fetch-tag + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ github.ref }} + + - 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 }} \ No newline at end of file From a43c5a9be90eda2cd347dbbc8eae77c53781c718 Mon Sep 17 00:00:00 2001 From: rpancham Date: Fri, 19 Apr 2024 12:53:47 +0530 Subject: [PATCH 2/2] Format file Signed-off-by: rpancham --- .github/workflows/create-tag-release.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/create-tag-release.yml b/.github/workflows/create-tag-release.yml index f506f13a..8db02825 100644 --- a/.github/workflows/create-tag-release.yml +++ b/.github/workflows/create-tag-release.yml @@ -4,7 +4,7 @@ on: workflow_dispatch: inputs: tag_name: - description: 'Tag name for the new release' + description: "Tag name for the new release" required: true permissions: @@ -28,14 +28,14 @@ jobs: 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: | + run: | echo "Old Tag=${{ steps.get_tag.outputs.old_tag_name }}" echo "NEW_TAG=${{ github.event.inputs.tag_name }}" >> $GITHUB_ENV echo "$(basename ${{ github.ref }})" - + - name: Check if tag exists id: check_tag run: | @@ -79,4 +79,4 @@ jobs: draft: false files: bin/* generate_release_notes: true - name: ${{ github.event.inputs.tag_name }} \ No newline at end of file + name: ${{ github.event.inputs.tag_name }}