From 33bc19f8748e70b3bc1a1bb23b81b9be9e7660ef Mon Sep 17 00:00:00 2001 From: Evan Luo Date: Sun, 1 Dec 2024 20:34:32 -0500 Subject: [PATCH] ci: improve release workflow robustness and error handling - Add fallback for existing release branch checkout - Implement conditional commit and push based on changes - Add success condition checks for PR and release creation - Remove automatic dev branch update step - Add error handling for existing PR and release --- .github/workflows/release.yml | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ee4ee86b..dc167601 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -52,7 +52,7 @@ jobs: run: | VERSION=$(node -p "require('./package.json').version") BRANCH="release/v${VERSION}" - git checkout -b $BRANCH + git checkout -b $BRANCH || git checkout $BRANCH npm run release:${{ github.event.inputs.release-type }} - name: Update package-lock.json @@ -61,18 +61,25 @@ jobs: - name: Commit Changes run: | NEW_VERSION=$(node -p "require('./package.json').version") - git add package.json package-lock.json - git commit -m "chore: bump version to ${NEW_VERSION}" - git push -u origin $BRANCH + if ! git diff --quiet; then + git add package.json package-lock.json + git commit -m "chore: bump version to ${NEW_VERSION}" + git push -u origin $BRANCH + else + echo "No changes to commit" + exit 1 + fi - name: Create Pull Request + if: success() env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | NEW_VERSION=$(node -p "require('./package.json').version") - gh pr create --base main --head "release/v${NEW_VERSION}" --title "Release v${NEW_VERSION}" --body "Automated release PR for version ${NEW_VERSION}" + gh pr create --base main --head "release/v${NEW_VERSION}" --title "Release v${NEW_VERSION}" --body "Automated release PR for version ${NEW_VERSION}" || echo "PR already exists" - name: Create GitHub Release (Draft) + if: success() env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | @@ -80,11 +87,4 @@ jobs: gh release create "v${NEW_VERSION}" \ --draft \ --title "v${NEW_VERSION}" \ - --notes "Release v${NEW_VERSION}" - - - name: Update dev branch - run: | - NEW_VERSION=$(node -p "require('./package.json').version") - git checkout dev - git merge "release/v${NEW_VERSION}" - git push origin dev \ No newline at end of file + --notes "Release v${NEW_VERSION}" || echo "Release already exists" \ No newline at end of file