-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: add release workflows for packages
- Loading branch information
1 parent
c43d916
commit 327b295
Showing
6 changed files
with
234 additions
and
59 deletions.
There are no files selected for viewing
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,39 @@ | ||
import { execSync } from "node:child_process"; | ||
import * as fs from "node:fs"; | ||
import { resolve } from "node:path"; | ||
|
||
if (process.argv.length === 2) { | ||
console.error("Expected one argument (directory)"); | ||
process.exit(1); | ||
} | ||
|
||
const packagePath = resolve(process.argv[2], "package.json"); | ||
if (!fs.existsSync(packagePath)) { | ||
console.error(`Could not find package.json at ${packagePath}`); | ||
process.exit(1); | ||
} | ||
|
||
const packageJson = JSON.parse(fs.readFileSync(packagePath, "utf8")); | ||
|
||
const nightly = process.argv.length === 4 && process.argv[3] === "true"; | ||
const tag = nightly ? "next" : "latest"; | ||
const latest = execSync(`npm view ${packageJson.name} dist-tags.${tag}`) | ||
.toString("utf8") | ||
.trim(); | ||
|
||
let changed = false; | ||
if (nightly) { | ||
const hash = latest.split("-").pop(); | ||
const result = execSync( | ||
`git diff --quiet ${hash} HEAD -- ${process.argv[2]} || echo changed`, | ||
) | ||
.toString("utf8") | ||
.trim(); | ||
changed = result === "changed"; | ||
} else if ( | ||
packageJson.version.localeCompare(latest, undefined, { numeric: true }) === 1 | ||
) { | ||
changed = true; | ||
} | ||
|
||
console.log(changed); |
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,18 @@ | ||
import * as fs from "node:fs"; | ||
import { resolve } from "node:path"; | ||
import { getDevVersion } from "./util.mjs"; | ||
|
||
if (process.argv.length === 2) { | ||
console.error("Expected one argument (directory)"); | ||
process.exit(1); | ||
} | ||
|
||
const packagePath = resolve(process.argv[2], "package.json"); | ||
if (!fs.existsSync(packagePath)) { | ||
console.error(`Could not find package.json at ${packagePath}`); | ||
process.exit(1); | ||
} | ||
|
||
const nightly = process.argv.length === 4 && process.argv[3] === "true"; | ||
const packageJson = JSON.parse(fs.readFileSync(packagePath, "utf8")); | ||
console.log(nightly ? getDevVersion(packageJson.version) : packageJson.version); |
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,23 @@ | ||
import { execSync } from "node:child_process"; | ||
|
||
export function getDevVersion(version) { | ||
const [major, minor, patch] = version | ||
.split(".") | ||
.map((num) => Number.parseInt(num)); | ||
|
||
const commitHash = getCommitHash(); | ||
return `${major}.${minor}.${patch + 1}-dev-${commitHash.substring(0, 7)}`; | ||
} | ||
|
||
function getCommitHash() { | ||
let commitHash; | ||
if ( | ||
typeof process.env.GITHUB_SHA === "string" && | ||
process.env.GITHUB_SHA !== "" | ||
) { | ||
commitHash = process.env.GITHUB_SHA; | ||
} else { | ||
commitHash = execSync("git rev-parse HEAD").toString("utf8"); | ||
} | ||
return commitHash; | ||
} |
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: Release core | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: "0 7 * * *" | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- packages/core/package.json | ||
|
||
jobs: | ||
check: | ||
name: Check version | ||
runs-on: ubuntu-latest | ||
outputs: | ||
version_changed: ${{ steps.check.outputs.version_changed }} | ||
nightly: ${{steps.nightly.outputs.nightly }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Enable Corepack | ||
run: corepack enable | ||
|
||
- name: Check nightly status | ||
id: nightly | ||
run: echo "nightly=${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}" >> "$GITHUB_OUTPUT" | ||
|
||
- name: Check version | ||
id: check | ||
run: | | ||
CHANGED=$(node .github/scripts/check-changed.mjs packages/core ${{ steps.nightly.outputs.nightly }}) | ||
echo "version_changed=$CHANGED" >> "$GITHUB_OUTPUT" | ||
publish: | ||
runs-on: ubuntu-latest | ||
needs: check | ||
if: needs.check.outputs.version_changed == 'true' | ||
env: | ||
nightly: ${{ needs.check.outputs.nightly }} | ||
permissions: | ||
id-token: write | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Enable Corepack | ||
run: corepack enable | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
registry-url: "https://registry.npmjs.org" | ||
cache: "yarn" | ||
|
||
- name: Install dependencies | ||
run: yarn install | ||
|
||
- name: Set nightly version | ||
if: env.nightly | ||
run: | | ||
VERSION=$(node .github/scripts/get-version.mjs @rbxts/centurion ${{ env.nightly }}) | ||
yarn workspace @rbxts/centurion version $VERSION | ||
- name: Publish @latest | ||
if: !env.nightly | ||
run: yarn workspace @rbxts/centurion npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
|
||
- name: Publish @next | ||
if: env.nightly | ||
run: yarn workspace @rbxts/centurion npm publish --tag next | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
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: Release UI | ||
|
||
on: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: "0 7 * * *" | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- packages/ui/package.json | ||
|
||
jobs: | ||
check: | ||
name: Check version | ||
runs-on: ubuntu-latest | ||
outputs: | ||
version_changed: ${{ steps.check.outputs.version_changed }} | ||
nightly: ${{steps.nightly.outputs.nightly }} | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Enable Corepack | ||
run: corepack enable | ||
|
||
- name: Check nightly status | ||
id: nightly | ||
run: echo "nightly=${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}" >> "$GITHUB_OUTPUT" | ||
|
||
- name: Check version | ||
id: check | ||
run: | | ||
CHANGED=$(node .github/scripts/check-changed.mjs packages/ui ${{ steps.nightly.outputs.nightly }}) | ||
echo "version_changed=$CHANGED" >> "$GITHUB_OUTPUT" | ||
publish: | ||
runs-on: ubuntu-latest | ||
needs: check | ||
if: needs.check.outputs.version_changed == 'true' | ||
env: | ||
nightly: ${{ needs.check.outputs.nightly }} | ||
permissions: | ||
id-token: write | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Enable Corepack | ||
run: corepack enable | ||
|
||
- uses: actions/setup-node@v4 | ||
with: | ||
node-version: 20 | ||
registry-url: "https://registry.npmjs.org" | ||
cache: "yarn" | ||
|
||
- name: Install dependencies | ||
run: yarn install | ||
|
||
- name: Set nightly version | ||
if: env.nightly | ||
run: | | ||
VERSION=$(node .github/scripts/get-version.mjs @rbxts/centurion-ui ${{ env.nightly }}) | ||
yarn workspace @rbxts/centurion-ui version $VERSION | ||
- name: Publish @latest | ||
if: !env.nightly | ||
run: yarn workspace @rbxts/centurion-ui npm publish | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
|
||
- name: Publish @next | ||
if: env.nightly | ||
run: yarn workspace @rbxts/centurion-ui npm publish --tag next | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |