feat(utils): make release script (#3290)
This commit is contained in:
parent
82e5128ba1
commit
f1524d3fcd
44
.github/workflows/pr-trigger.yml
vendored
44
.github/workflows/pr-trigger.yml
vendored
@ -15,10 +15,9 @@ jobs:
|
||||
pr:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout frontend mono repo
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
# We need to fetch all branches and commits so that Nx affected has a base to compare against.
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Check node version
|
||||
@ -32,45 +31,22 @@ jobs:
|
||||
with:
|
||||
node-version: ${{ steps.node-version.outputs.npmVersion }}
|
||||
|
||||
# Check SHAs
|
||||
- name: Derive appropriate SHAs for base and head for `nx affected` commands
|
||||
uses: nrwl/nx-set-shas@v3
|
||||
with:
|
||||
main-branch-name: develop
|
||||
|
||||
# See affected apps
|
||||
- name: Restore node_modules from cache
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: '**/node_modules'
|
||||
key: node_modules-${{ hashFiles('**/yarn.lock') }}
|
||||
|
||||
- name: Install root dependencies
|
||||
run: yarn install --frozen-lockfile
|
||||
|
||||
- name: See affected apps
|
||||
run: |
|
||||
nx_version=$(cat package.json | grep '"nx"' | cut -d ':' -f 2 | tr -d '",[:space:]')
|
||||
rm package.json yarn.lock
|
||||
yarn add nx@$nx_version
|
||||
|
||||
echo ">>>> debug"
|
||||
echo "NX Version: $nx_version"
|
||||
echo "NX_BASE: ${{ env.NX_BASE }}"
|
||||
echo "NX_HEAD: ${{ env.NX_HEAD }}"
|
||||
|
||||
# echo "Main branch name: ${{ github.base_ref || github.ref_name }}"
|
||||
# echo "git rev-parse HEAD: $(git rev-parse HEAD)"
|
||||
# echo "Head: ${{ github.head_ref }}"
|
||||
|
||||
# echo "command to execute: 'yarn nx print-affected --base=${{ github.base_ref || github.ref_name }} --head=${{ github.head_ref }} --select=projects'"
|
||||
|
||||
# merge_base=$(git merge-base origin/develop HEAD)
|
||||
# echo "git merge-base origin/develop HEAD: $merge_base"
|
||||
|
||||
# head_sha="${{ github.event.pull_request.head.sha || github.sha }}"
|
||||
# echo "Head SHA: $head_sha"
|
||||
|
||||
# echo "command to execute (without nx-set-sha): 'yarn nx print-affected --base=$merge_base --head=$head_sha --select=projects'"
|
||||
echo ">>>> eof debug"
|
||||
|
||||
# affected_1=$(yarn nx print-affected --base=$merge_base --head=$head_sha --select=projects || true)
|
||||
# echo -n "Affected projects (allowed to fail): $affected_1"
|
||||
|
||||
# affected=$(yarn nx print-affected --base=${{ github.base_ref || github.ref_name }} --head=${{ github.head_ref }} --select=projects)
|
||||
# echo -n "Affected projects: $affected"
|
||||
|
||||
affected="$(yarn nx print-affected --base=${{ env.NX_BASE }} --head=HEAD --select=projects)"
|
||||
echo -n "Affected projects: $affected"
|
||||
|
||||
|
@ -11,7 +11,8 @@
|
||||
"build:all": "nx run-many --all --target=build",
|
||||
"lint:all": "nx run-many --all --target=lint",
|
||||
"e2e:all": "nx run-many --all --target=e2e",
|
||||
"vegacapsule": "vegacapsule network bootstrap --config-path=../frontend-monorepo/vegacapsule/config.hcl"
|
||||
"vegacapsule": "vegacapsule network bootstrap --config-path=../frontend-monorepo/vegacapsule/config.hcl",
|
||||
"release": "git checkout develop ; git pull ; node scripts/make-release.js"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=16.15.1"
|
||||
@ -166,6 +167,7 @@
|
||||
"flush-promises": "^1.0.2",
|
||||
"glob": "^8.0.3",
|
||||
"husky": "^7.0.4",
|
||||
"inquirer": "^8.0.0",
|
||||
"jest": "27.5.1",
|
||||
"jest-canvas-mock": "^2.3.1",
|
||||
"jest-websocket-mock": "^2.3.0",
|
||||
|
82
scripts/make-release.js
Normal file
82
scripts/make-release.js
Normal file
@ -0,0 +1,82 @@
|
||||
const { execSync } = require('child_process');
|
||||
const inquirer = require('inquirer');
|
||||
|
||||
const getTags = (take) => {
|
||||
const tags = execSync(
|
||||
"git for-each-ref --sort=taggerdate --format '%(refname)' refs/tags"
|
||||
)
|
||||
.toString()
|
||||
.trim()
|
||||
.split('\n')
|
||||
.map((t) => t.replace('refs/tags/', ''))
|
||||
.reverse()
|
||||
.slice(0, take);
|
||||
return tags;
|
||||
};
|
||||
|
||||
const getReleaseBranches = () => {
|
||||
const branches = execSync('git branch --remote | grep origin/release/')
|
||||
.toString()
|
||||
.trim()
|
||||
.split('\n')
|
||||
.map((b) => b.trim().replace('origin/release/', ''));
|
||||
return branches;
|
||||
};
|
||||
|
||||
const release = (tag, branch) => {
|
||||
const steps = [
|
||||
`git checkout ${branch}`,
|
||||
'git pull',
|
||||
`git reset --hard ${tag}`,
|
||||
'git push --force',
|
||||
];
|
||||
try {
|
||||
for (const cmd of steps) {
|
||||
const result = execSync(cmd).toString();
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Could not make a release');
|
||||
}
|
||||
};
|
||||
|
||||
inquirer
|
||||
.prompt([
|
||||
{
|
||||
type: 'list',
|
||||
name: 'tag',
|
||||
message: 'What version would you like to release?',
|
||||
choices: getTags(),
|
||||
},
|
||||
{
|
||||
type: 'checkbox',
|
||||
name: 'envs',
|
||||
message: 'To what environment you wish to release?',
|
||||
choices: ['mainnet', ...getReleaseBranches()],
|
||||
validate(answer) {
|
||||
return answer.length > 0;
|
||||
},
|
||||
},
|
||||
])
|
||||
.then((answers) => {
|
||||
inquirer
|
||||
.prompt({
|
||||
type: 'confirm',
|
||||
name: 'sure',
|
||||
message: `Are you sure? This will release ${
|
||||
answers.tag
|
||||
} to ${answers.envs.join(', ')}`,
|
||||
})
|
||||
.then(() => {
|
||||
for (const env of answers.envs) {
|
||||
const branch = env === 'mainnet' ? 'master' : `release/${env}`;
|
||||
release(answers.tag, branch);
|
||||
}
|
||||
execSync('git checkout develop');
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log('Something went wrong', err.toString());
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log('Something went wrong', err.toString());
|
||||
});
|
Loading…
Reference in New Issue
Block a user