Skip to content

Commit

Permalink
ci: add release version approval step [no ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed Nov 24, 2023
1 parent 20fe081 commit 3d95bd0
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 3 deletions.
90 changes: 90 additions & 0 deletions .github/workflows/versionApproval.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Version Approval

on:
workflow_dispatch:
repository_dispatch:
types: [release-with-approval]

env:
NODE_OPTIONS: --max_old_space_size=4096
GH_TOKEN: ${{ secrets.GH_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
YARN_ENABLE_IMMUTABLE_INSTALLS: false

jobs:
init:
name: Init
runs-on: ubuntu-latest
outputs:
day: ${{ steps.get-day.outputs.day }}
ts: ${{ steps.get-timestamp.outputs.ts }}
steps:
- uses: actions/setup-node@v3
with:
node-version: 18

- uses: actions/checkout@v3

- name: Get day of the month
id: get-day
run: echo "day=$(node --eval "console.log(new Date().getDate())")" >> $GITHUB_OUTPUT

- name: Get timestamp
id: get-timestamp
run: echo "ts=$(node --eval "console.log(new Date().getTime())")" >> $GITHUB_OUTPUT
versioning:
needs: init
name: Determine Release Version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.determine-release-version.outputs.version }}
steps:
- uses: actions/setup-node@v3
with:
node-version: 18

- uses: actions/checkout@v3

- uses: actions/cache@v3
id: yarn-cache
with:
path: .yarn/cache
key: yarn-${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}

- uses: actions/cache@v3
id: global-daily-packages-cache
with:
path: .webiny/cached-packages
key: ${{ runner.os }}-${{ needs.init.outputs.day }}-${{ secrets.RANDOM_CACHE_KEY_SUFFIX }}

- name: Install dependencies
run: yarn --immutable

- name: Build packages
run: yarn build:quick

- uses: actions/cache@v3
with:
path: .webiny/cached-packages
key: packages-cache-${{ needs.init.outputs.ts }}

- name: Version packages
id: determine-release-version
shell: bash
run: |
echo "Creating version.txt"
touch version.txt
echo "Versioning packages..."
yarn release --type=${{ github.event.client_payload.type }} --tag=${{ github.event.client_payload.tag }} --version=${{ github.event.client_payload.version }} --createGithubRelease=${{ github.event.client_payload.createGithubRelease }} --printVersion | tee version.txt
echo "Setting output version: $(tail -n 1 version.txt)"
echo "version=$(tail -n 1 version.txt)" >> $GITHUB_OUTPUT
npm-release:
needs: [init, versioning]
name: Release ${{ needs.versioning.outputs.version }} ("${{ github.event.client_payload.tag }}")
runs-on: webiny-build-packages
environment: release
steps:
- uses: actions/setup-node@v3
with:
node-version: 18
10 changes: 9 additions & 1 deletion scripts/release/Release.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Release {
this.resetAllChanges = reset;
}

async execute() {
async versionPackages() {
this.__validateConfig();

this.logger.info("Attempting to release tag %s", this.tag);
Expand Down Expand Up @@ -98,6 +98,14 @@ class Release {
await execa("yarn", lernaVersionArgs, { stdio: "inherit" });
this.logger.info("Packages versioning completed");

// Read the new version
const lernaJSON = await loadJSON("lerna.json");
return { version: lernaJSON.version, tag: this.tag };
}

async execute() {
await this.versionPackages();

// Run `lerna` to publish packages
const lernaPublishArgs = [
"lerna",
Expand Down
10 changes: 8 additions & 2 deletions scripts/release/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { getReleaseType } = require("./releaseTypes");
yargs.version(false);

async function runRelease() {
const { type, tag, gitReset, version, createGithubRelease } = yargs.argv;
const { type, tag, gitReset, version, createGithubRelease, printVersion } = yargs.argv;

console.log({ type, tag, gitReset, version });
if (!type) {
Expand Down Expand Up @@ -34,7 +34,13 @@ async function runRelease() {
release.setCreateGithubRelease(createGithubRelease);
}

await release.execute();
if (printVersion) {
const { version } = await release.versionPackages();

console.log(version);
} else {
await release.execute();
}
}

(async () => {
Expand Down

0 comments on commit 3d95bd0

Please sign in to comment.