Skip to content

Commit

Permalink
Merge pull request #480 from EvanNotFound/dev
Browse files Browse the repository at this point in the history
ci: enhance release workflow with improved automation
  • Loading branch information
EvanNotFound authored Dec 2, 2024
2 parents 3857f60 + 8afad65 commit 085d49e
Showing 1 changed file with 54 additions and 41 deletions.
95 changes: 54 additions & 41 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,70 +21,83 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Checkout Repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Import GPG key

- name: Import GPG Key
id: import-gpg
uses: crazy-max/ghaction-import-gpg@v4
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
git_user_signingkey: true
git_commit_gpgsign: true

- name: Configure Git
run: |
git config --global user.email "${{ steps.import-gpg.outputs.email }}"
git config --global user.name "${{ steps.import-gpg.outputs.name }}"
git config --global commit.gpgsign true
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
registry-url: https://registry.npmjs.org/
- name: Install dependencies

- name: Install Dependencies
run: npm ci

- name: Create Release Branch and Update Version

- name: Determine New Version
id: new_version
run: |
VERSION=$(node -p "require('./package.json').version")
BRANCH="release/v${VERSION}"
git checkout -b $BRANCH || git checkout $BRANCH
npm run release:${{ github.event.inputs.release-type }}
- name: Update package-lock.json
run: npm install

- name: Commit Changes
CURRENT_VERSION=$(node -p "require('./package.json').version")
NEW_VERSION=$(npm version ${{ github.event.inputs.release-type }} --no-git-tag-version)
echo "current_version=$CURRENT_VERSION" >> $GITHUB_ENV
echo "new_version=$NEW_VERSION" >> $GITHUB_ENV
- name: Create or Checkout Release Branch
run: |
NEW_VERSION=$(node -p "require('./package.json').version")
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
BRANCH="release/v${{ env.new_version }}"
if git show-ref --quiet refs/heads/$BRANCH; then
git checkout $BRANCH
else
echo "No changes to commit"
exit 1
git checkout -b $BRANCH
fi
- name: Create Pull Request
if: success()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update Dependencies and Version
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}" || echo "PR already exists"
npm install
git add package.json package-lock.json
git commit -m "chore: bump version to ${{ env.new_version }}" || echo "No changes to commit"
- name: Create GitHub Release (Draft)
if: success()
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Push Changes
run: |
NEW_VERSION=$(node -p "require('./package.json').version")
gh release create "v${NEW_VERSION}" \
--draft \
--title "v${NEW_VERSION}" \
--notes "Release v${NEW_VERSION}" || echo "Release already exists"
BRANCH="release/v${{ env.new_version }}"
git push origin $BRANCH
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.PAT }}
commit-message: "chore: bump version to ${{ env.new_version }}"
branch: "release/v${{ env.new_version }}"
base: main
title: "Release v${{ env.new_version }}"
body: "Automated release PR for version ${{ env.new_version }}"
delete-branch: false
draft: false
labels: 'release, automated'
reviewers: 'EvanNotFound'
assignees: 'EvanNotFound'

- name: Create GitHub Release (Draft)
uses: ncipollo/release-action@v1
with:
tag: "v${{ env.new_version }}"
name: "v${{ env.new_version }}"
body: "Release v${{ env.new_version }}"
draft: true
prerelease: false

0 comments on commit 085d49e

Please sign in to comment.