-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Benji Visser <[email protected]>
- Loading branch information
Showing
4 changed files
with
140 additions
and
41 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,42 @@ | ||
name: Verify Version | ||
on: | ||
pull_request: | ||
branches: [main] | ||
types: [labeled, unlabeled, opened, synchronize] | ||
jobs: | ||
verify-version: | ||
runs-on: ubuntu-latest | ||
steps: | ||
# get main version | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: main | ||
- uses: martinbeentjes/npm-get-version-action@main | ||
id: main-version | ||
|
||
# get pr version | ||
- uses: actions/checkout@v4 | ||
- uses: martinbeentjes/npm-get-version-action@main | ||
id: pr-version | ||
|
||
- name: Setup | ||
uses: ./tooling/github/setup | ||
|
||
- run: pnpm add semver | ||
|
||
- uses: actions/github-script@v6 | ||
env: | ||
PR_VERSION: ${{steps.pr-version.outputs.current-version}} | ||
MAIN_VERSION: ${{steps.main-version.outputs.current-version}} | ||
with: | ||
script: | | ||
require('./.github/versioning.js').verify({ github, context, core }) | ||
block-prerelease: | ||
if: contains(github.event.pull_request.labels.*.name, 'prerelease') | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/github-script@v6 | ||
with: | ||
script: | | ||
core.setFailed(`PR with a prerelease label cannot be merged. Remove the label or change it to a release label and adjust the version as needed to fix.`) |
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,72 @@ | ||
const semver = require("semver"); | ||
|
||
const { PR_VERSION: pr, MAIN_VERSION: main } = process.env; | ||
|
||
const assertIsValidPrerelease = ({ github, context, core }) => { | ||
const pr_clean = pr.replace(/\-.+$/, ""); | ||
const pr_is_greater = semver.gt(pr_clean, main); | ||
|
||
if (pr_is_greater) { | ||
core.debug( | ||
`The pr version (${pr} -> ${pr_clean}) is higher than the main version (${main}).` | ||
); | ||
} else { | ||
core.setFailed( | ||
`The pr version (${pr}) is not greater than the main version (${main}). A pull request labeled with 'prerelease' must have a valid version bump.` | ||
); | ||
} | ||
const pr_is_prerelease = semver.prerelease(pr) !== null; | ||
if (pr_is_prerelease) { | ||
core.debug(`The pr version (${pr}) is a prerelease.`); | ||
} else { | ||
core.setFailed( | ||
`The pr version (${pr}) is not a prerelease. A pull request labeled with 'prerelease' must have a valid prerelease version (1.2.3-rc.1).` | ||
); | ||
} | ||
}; | ||
|
||
const assertIsValidRelease = ({ github, context, core }) => { | ||
const pr_is_greater = semver.gt(pr, main); | ||
if (pr_is_greater) { | ||
core.debug( | ||
`Success, the pr version (${pr}) is higher than the main version (${main}).` | ||
); | ||
} else { | ||
core.setFailed( | ||
`The pr version (${pr}) is not greater than the main version (${main}). A pull request labeled with 'release' must have a valid version bump.` | ||
); | ||
} | ||
const pr_is_prerelease = semver.prerelease(pr) !== null; | ||
if (!pr_is_prerelease) { | ||
core.debug(`The pr version (${pr}) is not a prerelease.`); | ||
} else { | ||
core.setFailed( | ||
`The pr version (${pr}) is a prerelease. A pull request labeled with 'release' cannot have a prerelease version (1.2.3-alpha.1 or 1.2.3-rc.1)` | ||
); | ||
} | ||
}; | ||
|
||
const assertIsUnchanged = ({ github, context, core }) => { | ||
if (pr.trim() === main.trim()) { | ||
core.debug( | ||
`Success, the pr version (${pr}) is the same as the main version (${main}).` | ||
); | ||
} else { | ||
core.setFailed( | ||
`The pr version (${pr}) is not the same as the main version (${main}). A pull request without a 'release' or 'prerelease' label cannot include a version bump.` | ||
); | ||
} | ||
}; | ||
|
||
exports.verify = ({ github, context, core }) => { | ||
const labels = (context.payload?.pull_request?.labels ?? []).map((l) => | ||
l.name.toLowerCase() | ||
); | ||
if (labels.includes("prerelease")) { | ||
return assertIsValidPrerelease({ github, context, core }); | ||
} | ||
if (labels.includes("release")) { | ||
return assertIsValidRelease({ github, context, core }); | ||
} | ||
assertIsUnchanged({ github, context, core }); | ||
}; |
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 |
---|---|---|
@@ -1,36 +1,39 @@ | ||
name: Publish bumpgen cli to npmjs | ||
name: Release to Npm | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
paths: | ||
- 'apps/cli/**' | ||
- "apps/cli/**" | ||
|
||
jobs: | ||
check: | ||
name: 'Check if release is needed' | ||
runs-on: 'ubuntu-latest' | ||
name: "Check if release is needed" | ||
runs-on: "ubuntu-latest" | ||
outputs: | ||
exists: ${{ steps.check-tag.outputs.exists }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/checkout@v4 | ||
# retrieves the version from package.json | ||
- uses: martinbeentjes/npm-get-version-action@main | ||
id: get-version | ||
# check if the tag exists on the repo | ||
- uses: mukunku/[email protected] | ||
id: check-tag | ||
with: | ||
tag: v${{ steps.get-version.outputs.current-version }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
release: | ||
name: 'Release' | ||
name: "Release" | ||
needs: check | ||
if: needs.check.outputs.exists == 'false' | ||
runs-on: 'ubuntu-latest' | ||
runs-on: "ubuntu-latest" | ||
permissions: | ||
contents: write | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/checkout@v4 | ||
- uses: martinbeentjes/npm-get-version-action@main | ||
id: get-version | ||
- uses: actions/create-release@v1 | ||
|
@@ -48,18 +51,8 @@ jobs: | |
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- uses: ./tooling/github/setup | ||
name: Install pnpm | ||
with: | ||
version: 8 | ||
run_install: false | ||
|
||
- name: Install Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version-file: ".nvmrc" | ||
cache: pnpm | ||
registry-url: https://registry.npmjs.org | ||
- name: Setup | ||
uses: ./tooling/github/setup | ||
|
||
- name: 📦️ Install dependencies | ||
run: pnpm install --frozen-lockfile | ||
|
@@ -68,4 +61,4 @@ jobs: | |
shell: bash | ||
run: pnpm publish apps/cli | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
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 |
---|---|---|
|
@@ -4,16 +4,16 @@ on: | |
push: | ||
branches: [main] | ||
paths: | ||
- 'packages/bumpgen-core/**' | ||
- "packages/bumpgen-core/**" | ||
|
||
jobs: | ||
check: | ||
name: 'Check if release is needed' | ||
runs-on: 'ubuntu-latest' | ||
name: "Check if release is needed" | ||
runs-on: "ubuntu-latest" | ||
outputs: | ||
exists: ${{ steps.check-tag.outputs.exists }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/checkout@v4 | ||
- uses: martinbeentjes/npm-get-version-action@main | ||
id: get-version | ||
- uses: mukunku/[email protected] | ||
|
@@ -22,15 +22,16 @@ jobs: | |
tag: v${{ steps.get-version.outputs.current-version }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
release: | ||
name: 'Release' | ||
name: "Release" | ||
needs: check | ||
if: needs.check.outputs.exists == 'false' | ||
runs-on: 'ubuntu-latest' | ||
runs-on: "ubuntu-latest" | ||
permissions: | ||
contents: write | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/checkout@v4 | ||
- uses: martinbeentjes/npm-get-version-action@main | ||
id: get-version | ||
- uses: actions/create-release@v1 | ||
|
@@ -42,29 +43,20 @@ jobs: | |
tag_name: v${{ steps.get-version.outputs.current-version}} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- uses: ./tooling/github/setup | ||
name: Install pnpm | ||
with: | ||
version: 8 | ||
run_install: false | ||
|
||
- name: Install Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version-file: ".nvmrc" | ||
cache: pnpm | ||
registry-url: https://registry.npmjs.org | ||
- name: Setup | ||
uses: ./tooling/github/setup | ||
|
||
- name: 📦️ Install dependencies | ||
run: pnpm install --frozen-lockfile | ||
|
||
- name: 🚀 Publish bumpgen-core to npm | ||
run: pnpm publish packages/bumpgen-core | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |