Prevent redundant releases in GitHub Actions
Added conditional logic to skip unnecessary release steps if the version tag already exists or if the version hasn't changed. This optimization avoids redundant operations by ensuring release-related jobs are executed only when needed, thus enhancing workflow efficiency.
This commit is contained in:
13
.github/workflows/CreateRelease.yml
vendored
13
.github/workflows/CreateRelease.yml
vendored
@@ -57,19 +57,22 @@ jobs:
|
|||||||
# Check if the version already exists as a tag
|
# Check if the version already exists as a tag
|
||||||
if git rev-parse "refs/tags/${{ env.VERSION }}" >/dev/null 2>&1; then
|
if git rev-parse "refs/tags/${{ env.VERSION }}" >/dev/null 2>&1; then
|
||||||
echo "Version ${{ env.VERSION }} already exists as a tag. No release will be created."
|
echo "Version ${{ env.VERSION }} already exists as a tag. No release will be created."
|
||||||
exit 1
|
echo "::set-output name=skip_release::true"
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Compare current version with previous tag
|
# Compare current version with previous tag
|
||||||
if [ "${{ env.VERSION }}" == "${{ env.PREVIOUS_TAG }}" ]; then
|
if [ "${{ env.VERSION }}" == "${{ env.PREVIOUS_TAG }}" ]; then
|
||||||
echo "Version has not changed. No release will be created."
|
echo "Version has not changed. No release will be created."
|
||||||
exit 1
|
echo "::set-output name=skip_release::true"
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
echo "::set-output name=skip_release::false"
|
||||||
shell: bash
|
shell: bash
|
||||||
continue-on-error: true
|
|
||||||
|
|
||||||
- name: Generate release notes
|
- name: Generate release notes
|
||||||
id: generate_notes
|
id: generate_notes
|
||||||
|
if: steps.check_version.outputs.skip_release == 'false'
|
||||||
run: |
|
run: |
|
||||||
echo "Generating release notes from ${{ env.PREVIOUS_TAG }} to HEAD..."
|
echo "Generating release notes from ${{ env.PREVIOUS_TAG }} to HEAD..."
|
||||||
repo_url=$(git config --get remote.origin.url)
|
repo_url=$(git config --get remote.origin.url)
|
||||||
@@ -81,6 +84,7 @@ jobs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
- name: Set Git user
|
- name: Set Git user
|
||||||
|
if: steps.check_version.outputs.skip_release == 'false'
|
||||||
run: |
|
run: |
|
||||||
git config --local user.name "GitHub Actions"
|
git config --local user.name "GitHub Actions"
|
||||||
git config --local user.email "actions@github.com"
|
git config --local user.email "actions@github.com"
|
||||||
@@ -88,6 +92,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Create temporary branch
|
- name: Create temporary branch
|
||||||
id: create_temp_branch
|
id: create_temp_branch
|
||||||
|
if: steps.check_version.outputs.skip_release == 'false'
|
||||||
run: |
|
run: |
|
||||||
git checkout --orphan release/v${{ env.VERSION }}
|
git checkout --orphan release/v${{ env.VERSION }}
|
||||||
git reset
|
git reset
|
||||||
@@ -98,6 +103,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Create and push tag
|
- name: Create and push tag
|
||||||
id: create_tag
|
id: create_tag
|
||||||
|
if: steps.check_version.outputs.skip_release == 'false'
|
||||||
run: |
|
run: |
|
||||||
git tag ${{ env.VERSION }}
|
git tag ${{ env.VERSION }}
|
||||||
git push origin ${{ env.VERSION }}
|
git push origin ${{ env.VERSION }}
|
||||||
@@ -106,6 +112,7 @@ jobs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
- name: Release
|
- name: Release
|
||||||
|
if: steps.check_version.outputs.skip_release == 'false'
|
||||||
uses: softprops/action-gh-release@v2
|
uses: softprops/action-gh-release@v2
|
||||||
with:
|
with:
|
||||||
tag_name: ${{ env.VERSION }}
|
tag_name: ${{ env.VERSION }}
|
||||||
|
Reference in New Issue
Block a user