-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor auto beta release to be publish branch
- Loading branch information
1 parent
dff62c1
commit 47bf56d
Showing
4 changed files
with
114 additions
and
145 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 @@ | ||
name: Publish Branch | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- dev | ||
|
||
jobs: | ||
release_candidate: | ||
runs-on: ubuntu-latest | ||
env: | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
BRANCH_NAME: ${{ github.head_ref || github.ref_name }} | ||
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 | tr -d '"')" >> $GITHUB_ENV | ||
|
||
# get the sort SHA and add it into the environment variables | ||
- name: Get short SHA | ||
run: echo "SHORT_SHA=${GITHUB_SHA::7}" >> $GITHUB_ENV | ||
|
||
# get the package name so the workflow can be reusable between projects | ||
# - name: Get current package.json name | ||
# run: echo "PACKAGE_NAME=$(npm pkg get name | tr -d '"')" >> $GITHUB_ENV | ||
|
||
- name: Setup Branch Release Candidate Version | ||
run: echo "NEW_VERSION=$PACKAGE_VERSION-$BRANCH_NAME.$SHORT_SHA" >> $GITHUB_ENV | ||
|
||
- name: Update Package.json Version with Release Candidate Version | ||
run: node ./update-branch-version.js --version $NEW_VERSION | ||
|
||
- name: Publish a new branch release candidate version | ||
run: npm publish --tag $BRANCH_NAME | ||
env: | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
|
||
# This comment only works for Pull Requests | ||
# - 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: `Release candidate released with the last commit 🚀 | ||
|
||
# \`\`\` | ||
# yarn add ${{ env.PACKAGE_NAME}}@${{ env.NEW_VERSION }} | ||
# \`\`\` | ||
# or | ||
# \`\`\` | ||
# npm install ${{ env.PACKAGE_NAME}}@${{ env.NEW_VERSION }} | ||
# \`\`\` | ||
# ` | ||
# }) |
This file was deleted.
Oops, something went wrong.
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,37 @@ | ||
/* eslint-disable prefer-destructuring */ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const util = require("util"); | ||
const exec = util.promisify(require("child_process").exec); | ||
const args = require("minimist")(process.argv.slice(2)); | ||
|
||
const version = args["version"]; | ||
|
||
console.log("version: ", version); | ||
|
||
const runCommand = async (command) => { | ||
return new Promise((resolve) => { | ||
exec(command, (error, stdout, stderr) => { | ||
resolve({ error, stdout, stderr }); | ||
}); | ||
}); | ||
}; | ||
|
||
/** | ||
* @NOTE: This can't be done by only using the workflow, because when we try to update | ||
* the version to the desired version, we get an error about wrong version format, | ||
* but directly on CI it works as expected. | ||
*/ | ||
const UpdateBranchVersion = async () => { | ||
// update the release candidate version on package.json | ||
const { error } = await runCommand(`npm version ${version}`); | ||
|
||
if (error) { | ||
console.error(error); | ||
return; | ||
} | ||
|
||
// the release candidate version is already updated on package.json on the next line | ||
console.log("Next Release Candidate version: ", `${version}`); | ||
}; | ||
|
||
UpdateBranchVersion(); |