Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
77 changes: 77 additions & 0 deletions .github/workflows/publish-branch.yaml
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"
Comment thread
bigtimebuddy marked this conversation as resolved.
Outdated
registry-url: "https://registry.npmjs.org"
cache: "yarn"
Comment thread
danielbarion marked this conversation as resolved.
Outdated

- name: Install dev dependencies
run: yarn install
Comment thread
bigtimebuddy marked this conversation as resolved.
Outdated

- name: Setup npm credentials file
run: echo "//registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN" >> .npmrc
Comment thread
danielbarion marked this conversation as resolved.
Outdated

# - 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
Comment thread
danielbarion marked this conversation as resolved.
Outdated

- name: Publish a new branch release candidate version
run: npm publish --tag $BRANCH_NAME
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
Comment thread
danielbarion marked this conversation as resolved.
Outdated

# 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 }}
# \`\`\`
# `
# })
Comment thread
bigtimebuddy marked this conversation as resolved.
Outdated
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@
"esbuild": "^0.19.0",
"eslint": "^8.38.0",
"eslint-plugin-jest": "^27.6.0",
"eslint-plugin-no-mixed-operators": "^1.1.1",
"eslint-plugin-jsdoc": "^48.0.0",
"eslint-plugin-no-mixed-operators": "^1.1.1",
"fs-extra": "^11.2.0",
"glob": "^8.1.0",
"http-server": "^14.1.1",
Expand All @@ -100,6 +100,7 @@
"jest-extended": "^1.2.1",
"jest-raw-loader": "^1.0.1",
"lint-staged": "^13.3.0",
"minimist": "^1.2.8",
"nodemon": "^3.0.2",
"npm-run-all": "^4.1.5",
"pixelmatch": "^5.3.0",
Expand Down
37 changes: 37 additions & 0 deletions update-branch-version.js
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}`);
Comment thread
danielbarion marked this conversation as resolved.
Outdated

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();