Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add beta release workflow #1148

Merged
merged 6 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .github/workflows/beta-release.yaml
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'
gabrieljablonski marked this conversation as resolved.
Show resolved Hide resolved

- 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 }}
\`\`\`
`
})
7 changes: 3 additions & 4 deletions .github/workflows/bundlesize.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run Bundlesize
name: Bundlesize

on:
workflow_call:
Expand All @@ -7,8 +7,8 @@ jobs:
bundlesize:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4

- name: Install dev dependencies
run: yarn install
Expand All @@ -18,4 +18,3 @@ jobs:

- name: Bundlesize
run: yarn run bundlesize

12 changes: 6 additions & 6 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run basic linting and testing
name: Lint

on:
workflow_call:
Expand All @@ -7,8 +7,8 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4

- name: Install dev dependencies
run: yarn install
Expand All @@ -20,11 +20,11 @@ jobs:
needs: lint
strategy:
matrix:
version: [16, 18]
version: [16, 18, 20]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.version }}

Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ jobs:
if: 'github.event.pull_request.draft == false'
uses: ./.github/workflows/bundlesize.yaml

beta_release:
uses: ./.github/workflows/beta-release.yaml
# allow the children job to have access to the secrets of the repository
secrets: inherit

fail_if_pull_request_is_draft:
if: github.event.pull_request.draft == true
runs-on: ubuntu-18.04
Expand Down
29 changes: 14 additions & 15 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,26 @@ name: Mark stale issues and pull requests

on:
schedule:
- cron: '00 12 * * *'
- cron: '00 12 * * *'

jobs:
stale:

runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write

steps:
- uses: actions/stale@v5
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-issue-stale: 90
days-before-issue-close: 30
days-before-pr-stale: 90
days-before-pr-close: 30
stale-issue-message: 'This issue is stale because it has not seen activity in 30 days. Remove the `stale` label or comment within 14 days, or it will be closed.'
stale-pr-message: 'This pull request is stale because it has not seen activity in 30 days. Remove the `stale` label or comment within 14 days, or it will be closed.'
stale-issue-label: 'stale'
stale-pr-label: 'stale'
exempt-issue-labels: 'help-wanted,v6'
exempt-pr-labels: 'help-wanted,v6'
- uses: actions/stale@v5
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
days-before-issue-stale: 90
days-before-issue-close: 30
days-before-pr-stale: 90
days-before-pr-close: 30
stale-issue-message: 'This issue is stale because it has not seen activity in 30 days. Remove the `stale` label or comment within 14 days, or it will be closed.'
stale-pr-message: 'This pull request is stale because it has not seen activity in 30 days. Remove the `stale` label or comment within 14 days, or it will be closed.'
stale-issue-label: 'stale'
stale-pr-label: 'stale'
exempt-issue-labels: 'help-wanted,v6'
exempt-pr-labels: 'help-wanted,v6'
77 changes: 77 additions & 0 deletions beta-release.js
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`)
}
Comment on lines +20 to +75
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The AutoBetaRelease function is well-structured and handles the beta release process effectively. However, consider adding error handling for JSON parsing and command execution failures to enhance robustness.

+ try {
+   const arrayOfBetaReleases = JSON.parse(stdout).filter((version) =>
+     version.includes(`${package.version}-beta.${issueNumber}`),
+   );
+ } catch (error) {
+   console.error('Failed to parse JSON:', error);
+   return;
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
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`)
}
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
try {
const arrayOfBetaReleases = JSON.parse(stdout).filter((version) =>
version.includes(`${package.version}-beta.${issueNumber}`),
);
} catch (error) {
console.error('Failed to parse JSON:', error);
return;
}
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()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider wrapping the AutoBetaRelease function call in a condition or exporting it as a module to provide more control over its execution.

+ if (require.main === module) {
+   AutoBetaRelease();
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
AutoBetaRelease()
if (require.main === module) {
AutoBetaRelease();
}

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"jest-environment-jsdom": "29.4.3",
"jest-transform-css": "6.0.1",
"lint-staged": "13.1.2",
"minimist": "^1.2.8",
"postcss": "8.4.21",
"prettier": "2.8.4",
"process": "^0.11.10",
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5696,7 +5696,7 @@ minimist-options@4.1.0:
is-plain-obj "^1.1.0"
kind-of "^6.0.3"

minimist@^1.2.0, minimist@^1.2.3, minimist@^1.2.5, minimist@^1.2.6:
minimist@^1.2.0, minimist@^1.2.3, minimist@^1.2.5, minimist@^1.2.6, minimist@^1.2.8:
version "1.2.8"
resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.8.tgz#c1a464e7693302e082a075cee0c057741ac4772c"
integrity sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==
Expand Down
Loading