|
3 | 3 | push: |
4 | 4 | branches: |
5 | 5 | - master |
| 6 | + |
| 7 | +env: |
| 8 | + HUSKY: 0 |
| 9 | + |
6 | 10 | jobs: |
7 | 11 | release: |
| 12 | + permissions: |
| 13 | + contents: write # for release publishing |
| 14 | + pull-requests: write # for creating PRs |
| 15 | + issues: write # additional permission that might be needed |
| 16 | + |
8 | 17 | name: Release |
| 18 | + env: |
| 19 | + commitmsg: ${{ github.event.head_commit.message }} |
9 | 20 | runs-on: ubuntu-latest |
10 | 21 | steps: |
11 | | - - name: Checkout |
12 | | - uses: actions/checkout@v2 |
| 22 | + - name: Checkout repository |
| 23 | + uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3 |
13 | 24 | with: |
14 | 25 | fetch-depth: 0 |
15 | 26 | - name: Setup Node.js |
16 | | - uses: actions/setup-node@v3 |
| 27 | + uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v3 |
17 | 28 | with: |
18 | | - node-version: 20 |
| 29 | + node-version: lts/* |
| 30 | + cache: 'yarn' |
19 | 31 | - name: Install dependencies |
20 | 32 | run: yarn install --frozen-lockfile --non-interactive |
| 33 | + - run: yarn build |
21 | 34 | - name: Release |
| 35 | + id: semantic_release |
22 | 36 | env: |
23 | 37 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
24 | 38 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
25 | 39 | run: npx semantic-release |
| 40 | + - name: Create PR with release changes |
| 41 | + if: ${{ success() && steps.semantic_release.outcome == 'success' }} |
| 42 | + env: |
| 43 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 45 | + run: | |
| 46 | + # Check if there are any changes to commit |
| 47 | + if [[ -n $(git status --porcelain) ]]; then |
| 48 | + # Get the version from package.json |
| 49 | + VERSION=$(node -p "require('./package.json').version") |
| 50 | + BRANCH_NAME="release/v${VERSION}" |
| 51 | + |
| 52 | + echo "Creating PR for release version: ${VERSION}" |
| 53 | + |
| 54 | + # Create and switch to new branch |
| 55 | + git checkout -b $BRANCH_NAME |
| 56 | + |
| 57 | + # Configure git |
| 58 | + git config --local user.email "[email protected]" |
| 59 | + git config --local user.name "GitHub Action" |
| 60 | + |
| 61 | + # Add and commit changes (only add files that exist) |
| 62 | + git add package.json || true |
| 63 | + git add yarn.lock || true |
| 64 | + git add CHANGELOG.md || true |
| 65 | + |
| 66 | + # Check if there are actually changes to commit after adding |
| 67 | + if [[ -n $(git diff --cached --name-only) ]]; then |
| 68 | + git commit -m "chore(release): ${VERSION}" |
| 69 | + |
| 70 | + # Push the branch |
| 71 | + git push origin $BRANCH_NAME |
| 72 | + |
| 73 | + # Create PR using GitHub CLI |
| 74 | + gh pr create \ |
| 75 | + --title "chore(release): ${VERSION}" \ |
| 76 | + --body "Automated release PR for version ${VERSION} |
| 77 | +
|
| 78 | + This PR contains: |
| 79 | + - Updated package.json version |
| 80 | + - Updated yarn.lock (if changed) |
| 81 | + - Updated CHANGELOG.md |
| 82 | +
|
| 83 | + Please review and merge to complete the release process." \ |
| 84 | + --head $BRANCH_NAME \ |
| 85 | + --base master |
| 86 | + |
| 87 | + echo "Created PR for release ${VERSION}" |
| 88 | + else |
| 89 | + echo "No changes to commit after staging files" |
| 90 | + git checkout master |
| 91 | + git branch -D $BRANCH_NAME |
| 92 | + fi |
| 93 | + else |
| 94 | + echo "No changes detected after semantic-release" |
| 95 | + fi |
0 commit comments