|
| 1 | +name: Beta Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + |
| 6 | +jobs: |
| 7 | + beta_release: |
| 8 | + runs-on: ubuntu-latest |
| 9 | + env: |
| 10 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 11 | + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v4 |
| 14 | + with: |
| 15 | + ref: ${{ github.head_ref }} |
| 16 | + - uses: actions/setup-node@v4 |
| 17 | + with: |
| 18 | + node-version: '16.x' |
| 19 | + registry-url: 'https://registry.npmjs.org' |
| 20 | + cache: 'yarn' |
| 21 | + |
| 22 | + - name: Install dev dependencies |
| 23 | + run: yarn install |
| 24 | + |
| 25 | + - name: Setup npm credentials file |
| 26 | + run: echo "//registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN" >> .npmrc |
| 27 | + |
| 28 | + - name: Setup git credentials |
| 29 | + run: | |
| 30 | + git config --global user.name 'Auto Release Bot' |
| 31 | + git config --global user.email 'auto-release-bot@users.noreply.github.com' |
| 32 | +
|
| 33 | + - name: Get current package.json version |
| 34 | + run: echo "PACKAGE_VERSION=$(npm pkg get version)" >> $GITHUB_ENV |
| 35 | + |
| 36 | + - name: First beta release for this pull request |
| 37 | + if: contains(env.PACKAGE_VERSION, 'beta') == false |
| 38 | + run: echo "NEW_VERSION=$(npm version prerelease --no-git-tag-version --preid=beta.$GITHUB_PR_NUMBER)" >> $GITHUB_ENV |
| 39 | + env: |
| 40 | + GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }} |
| 41 | + |
| 42 | + - name: Subsequent beta releases for this pull request |
| 43 | + if: contains(env.PACKAGE_VERSION, 'beta') |
| 44 | + run: echo "NEW_VERSION=$(npm version prerelease --no-git-tag-version --preid=beta)" >> $GITHUB_ENV |
| 45 | + env: |
| 46 | + GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }} |
| 47 | + |
| 48 | + - name: Release a new beta version |
| 49 | + run: npm publish --tag beta |
| 50 | + env: |
| 51 | + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
| 52 | + |
| 53 | + - name: Save new release version |
| 54 | + run: | |
| 55 | + git add ./package.json |
| 56 | + git commit -m "chore: bump version to $NEW_VERSION" |
| 57 | + git push |
| 58 | +
|
| 59 | + - uses: actions/github-script@v6 |
| 60 | + with: |
| 61 | + script: | |
| 62 | + github.rest.issues.createComment({ |
| 63 | + issue_number: context.issue.number, |
| 64 | + owner: context.repo.owner, |
| 65 | + repo: context.repo.repo, |
| 66 | + body: `Beta version released with the last commit 🚀 |
| 67 | +
|
| 68 | + \`\`\` |
| 69 | + yarn add react-tooltip@${{ env.NEW_VERSION }} |
| 70 | + \`\`\` |
| 71 | + or |
| 72 | + \`\`\` |
| 73 | + npm install react-tooltip@${{ env.NEW_VERSION }} |
| 74 | + \`\`\` |
| 75 | + ` |
| 76 | + }) |
0 commit comments