-
-
Notifications
You must be signed in to change notification settings - Fork 530
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1148 from ReactTooltip/feat/automated-beta-releases
feat: add beta release workflow
- Loading branch information
Showing
8 changed files
with
170 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
name: Beta Release | ||
|
||
on: | ||
workflow_call: | ||
|
||
jobs: | ||
beta_release: | ||
runs-on: ubuntu-latest | ||
env: | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.head_ref }} | ||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: '16.x' | ||
registry-url: 'https://registry.npmjs.org' | ||
cache: 'yarn' | ||
|
||
- name: Install dev dependencies | ||
run: yarn install | ||
|
||
- name: Setup npm credentials file | ||
run: echo "//registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN" >> .npmrc | ||
|
||
- name: Setup git credentials | ||
run: | | ||
git config --global user.name 'Auto Release Bot' | ||
git config --global user.email 'auto-release-bot@users.noreply.github.com' | ||
- name: Get current package.json version | ||
run: echo "PACKAGE_VERSION=$(npm pkg get version)" >> $GITHUB_ENV | ||
|
||
- name: Setup Beta Release Version | ||
run: node beta-release.js --issue $GITHUB_PR_NUMBER | ||
env: | ||
GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }} | ||
|
||
- name: Release a new beta version | ||
run: npm publish --tag beta | ||
env: | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
|
||
- uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
body: `Beta version released with the last commit 🚀 | ||
\`\`\` | ||
yarn add react-tooltip@${{ env.NEW_VERSION }} | ||
\`\`\` | ||
or | ||
\`\`\` | ||
npm install react-tooltip@${{ env.NEW_VERSION }} | ||
\`\`\` | ||
` | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const util = require('util') | ||
const exec = util.promisify(require('child_process').exec) | ||
const package = require('./package.json') | ||
|
||
const args = require('minimist')(process.argv.slice(2)) | ||
|
||
const issueNumber = args['issue'] | ||
|
||
console.log(issueNumber) | ||
|
||
const runCommand = async (command) => { | ||
return new Promise((resolve) => { | ||
exec(command, (error, stdout, stderr) => { | ||
resolve({ error, stdout, stderr }) | ||
}) | ||
}) | ||
} | ||
|
||
const AutoBetaRelease = async () => { | ||
// get all the versions of the package from npm | ||
const { stdout } = await runCommand(`npm view . versions --json`) | ||
|
||
// show npm published versions of this package | ||
console.log(stdout) | ||
|
||
// check if there is a beta release with the same issue number on published versions | ||
const arrayOfBetaReleases = JSON.parse(stdout).filter((version) => | ||
version.includes(`${package.version}-beta.${issueNumber}`), | ||
) | ||
|
||
let fullLastBetaRelease = null | ||
|
||
// if yes, get the latest beta release. Output: 1.0.0-beta.1.rc.0 | ||
if (arrayOfBetaReleases.length) { | ||
fullLastBetaRelease = arrayOfBetaReleases[arrayOfBetaReleases.length - 1] | ||
} | ||
|
||
console.log('Last Beta Release: ', fullLastBetaRelease) | ||
|
||
let nextBetaReleaseVersion = 0 | ||
|
||
if (fullLastBetaRelease) { | ||
const lastBetaReleaseRCVersionArray = fullLastBetaRelease.match(/rc.+[0-9]+/g) | ||
|
||
const lastBetaReleaseRCVersion = | ||
lastBetaReleaseRCVersionArray && lastBetaReleaseRCVersionArray.length | ||
? lastBetaReleaseRCVersionArray[0] | ||
: null | ||
|
||
const lastBetaReleaseVersion = lastBetaReleaseRCVersion | ||
? lastBetaReleaseRCVersion.split('.')[1] | ||
: 0 | ||
|
||
nextBetaReleaseVersion = parseInt(lastBetaReleaseVersion, 10) + 1 | ||
} | ||
|
||
// next beta release version. Output: 1.0.0-beta.1.rc.1 | ||
const nextBetaReleaseVesionFull = `${package.version}-beta.${issueNumber}.rc.${nextBetaReleaseVersion}` | ||
|
||
// update the beta version on package.json | ||
const { error } = await runCommand( | ||
`npm version ${nextBetaReleaseVesionFull} --no-git-tag-version`, | ||
) | ||
|
||
if (error) { | ||
console.error(error) | ||
return | ||
} | ||
|
||
// the beta version is already updated on package.json on the next line | ||
console.log('Next Beta version: ', `${nextBetaReleaseVesionFull}`) | ||
|
||
await runCommand(`echo "NEW_VERSION=${nextBetaReleaseVesionFull}" >> $GITHUB_ENV`) | ||
} | ||
|
||
AutoBetaRelease() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters