|
6 | 6 | bump: |
7 | 7 | description: 'Version bump type' |
8 | 8 | required: true |
| 9 | + default: 'patch' |
9 | 10 | type: choice |
10 | 11 | options: |
11 | 12 | - patch |
12 | 13 | - minor |
13 | 14 | - major |
14 | 15 | overview: |
15 | | - description: 'Release overview (will be placed at top of notes)' |
16 | | - required: true |
| 16 | + description: 'Overview for the release notes (optional)' |
| 17 | + required: false |
| 18 | + type: string |
17 | 19 |
|
18 | 20 | jobs: |
19 | 21 | release: |
20 | | - name: Create tag and release |
| 22 | + name: Create Release |
21 | 23 | runs-on: ubuntu-latest |
| 24 | + env: |
| 25 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 26 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
22 | 27 |
|
23 | 28 | steps: |
24 | | - - name: Checkout target branch |
| 29 | + - name: Checkout repo |
25 | 30 | uses: actions/checkout@v4 |
26 | 31 | with: |
27 | | - ref: ${{ github.ref_name }} |
| 32 | + fetch-depth: 0 |
28 | 33 |
|
29 | 34 | - name: Set up Node.js |
30 | 35 | uses: actions/setup-node@v4 |
31 | 36 | with: |
32 | | - node-version: '20' |
33 | | - |
34 | | - - name: Install dependencies |
35 | | - run: npm ci |
| 37 | + node-version: 20 |
36 | 38 |
|
37 | | - - name: Push version bump and tag |
| 39 | + - name: Configure git |
38 | 40 | run: | |
39 | 41 | git config user.name "github-actions" |
40 | 42 | git config user.email "[email protected]" |
41 | | - npm version ${{ github.event.inputs.bump }} --no-git-tag-version |
42 | | - version=$(jq -r .version package.json) |
43 | | - git add package.json package-lock.json |
44 | | - git commit -m "Bump version to $version" |
45 | | - git tag $version |
46 | | - git push origin ${{ github.ref_name }} |
47 | | - git push origin $version |
48 | 43 |
|
49 | | - - name: Get merged PR titles and format release notes |
50 | | - id: changelog |
51 | | - run: | |
52 | | - git fetch --tags |
| 44 | + - name: Fetch tags |
| 45 | + run: git fetch --tags |
53 | 46 |
|
54 | | - # Get most recent and previous tags |
55 | | - tags=($(git tag --sort=-creatordate)) |
56 | | - new_tag="${tags[0]}" |
57 | | - prev_tag="${tags[1]}" |
| 47 | + - name: Bump version |
| 48 | + run: | |
| 49 | + NEW_VERSION=$(npm version ${{ github.event.inputs.bump }} --no-git-tag-version) |
| 50 | + echo "VERSION=${NEW_VERSION}" >> $GITHUB_ENV |
58 | 51 |
|
59 | | - if [ -z "$prev_tag" ]; then |
60 | | - echo "Warning: No previous tag found. Skipping full changelog link." |
61 | | - changelog="" |
62 | | - else |
63 | | - changelog="**Full Changelog**: https://github.com/${{ github.repository }}/compare/$prev_tag...$new_tag" |
64 | | - fi |
| 52 | + - name: Commit and tag version bump |
| 53 | + run: | |
| 54 | + git commit -am "Bump version to ${VERSION}" |
| 55 | + git tag ${VERSION} |
| 56 | + git push origin HEAD |
| 57 | + git push origin ${VERSION} |
65 | 58 |
|
66 | | - prs=$(gh pr list --state merged --base "${{ github.ref_name }}" --json title,mergedAt --jq '[.[] | select(.mergedAt != null) | .title]') |
67 | | - joined=$(echo "$prs" | jq -r '.[]' | sed 's/^/* /') |
| 59 | + - name: Get previous tag |
| 60 | + id: previous_tag |
| 61 | + run: | |
| 62 | + PREV_TAG=$(git tag --sort=-creatordate | grep -v ${VERSION} | head -n 1) |
| 63 | + echo "PREV_TAG=$PREV_TAG" >> $GITHUB_ENV |
| 64 | + echo "prev_tag=$PREV_TAG" >> $GITHUB_OUTPUT |
68 | 65 |
|
| 66 | + - name: Generate release notes from merged PRs |
| 67 | + id: release_notes |
| 68 | + run: | |
| 69 | + OVERVIEW="${{ github.event.inputs.overview }}" |
| 70 | + NOTES=$(git log ${{ env.PREV_TAG }}..HEAD --pretty=format:"* %s" --merges) |
| 71 | + echo -e "${OVERVIEW}\n\n## What's Changed\n${NOTES}\n\n**Full Changelog**: https://github.com/${{ github.repository }}/compare/${{ env.PREV_TAG }}...${{ env.VERSION }}" > release-notes.md |
| 72 | + cat release-notes.md |
69 | 73 | echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV |
70 | | - echo "${{ github.event.inputs.overview }}" >> $GITHUB_ENV |
71 | | - echo "" >> $GITHUB_ENV |
72 | | - echo "## What's Changed" >> $GITHUB_ENV |
73 | | - echo "$joined" >> $GITHUB_ENV |
74 | | - echo "" >> $GITHUB_ENV |
75 | | - echo "$changelog" >> $GITHUB_ENV |
| 74 | + cat release-notes.md >> $GITHUB_ENV |
76 | 75 | echo "EOF" >> $GITHUB_ENV |
77 | | - env: |
78 | | - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
79 | 76 |
|
80 | | - - name: Create GitHub release |
| 77 | + - name: Create GitHub Release |
81 | 78 | run: | |
82 | | - git fetch --tags |
83 | | - tag=$(git describe --tags --abbrev=0) |
84 | | - gh release create "$tag" --title "$tag" --notes "${{ env.RELEASE_NOTES }}" |
85 | | - env: |
86 | | - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
87 | | - |
88 | | - readme-changelog: |
89 | | - name: Publish changelog to Readme |
90 | | - needs: release |
91 | | - runs-on: ubuntu-latest |
92 | | - |
93 | | - steps: |
94 | | - - name: Checkout repo |
95 | | - uses: actions/checkout@v4 |
96 | | - |
97 | | - - name: Extract release data |
98 | | - id: release |
99 | | - run: | |
100 | | - echo "title=${{ github.ref_name }}" >> $GITHUB_OUTPUT |
101 | | - body=$(gh release view ${{ github.ref_name }} --json body --jq .body) |
102 | | - { |
103 | | - echo "body<<EOF" |
104 | | - echo "$body" |
105 | | - echo "EOF" |
106 | | - } >> $GITHUB_OUTPUT |
107 | | - env: |
108 | | - GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 79 | + gh release create "${VERSION}" \ |
| 80 | + --title "${VERSION}" \ |
| 81 | + --notes "$(cat release-notes.md)" |
109 | 82 |
|
110 | 83 | - name: Publish changelog to Readme |
111 | 84 | env: |
112 | 85 | README_API_KEY: ${{ secrets.README_API_KEY }} |
113 | 86 | run: | |
114 | | - jq -n --arg title "Node.js Unified SDK v${{ steps.release.outputs.title }}" \ |
115 | | - --arg body "${{ steps.release.outputs.body }}" \ |
| 87 | + jq -n --arg title "Node.js Unified SDK v${VERSION}" \ |
| 88 | + --arg body "$(<release-notes.md)" \ |
116 | 89 | '{ |
117 | 90 | title: $title, |
118 | 91 | content: { |
|
0 commit comments