From 30dc9694574e0a1d3c399ed0c7223898ad540227 Mon Sep 17 00:00:00 2001 From: mrunalC27 Date: Mon, 30 Nov 2026 20:37:32 +0530 Subject: [PATCH] chore: simplify build and release workflows --- .github/pull_request_template.md | 3 -- .github/workflows/ci.yml | 31 +++++++++++ .github/workflows/pr-title.yml | 21 -------- .github/workflows/release.yml | 89 +++++++++++++++++--------------- CONTRIBUTING.md | 62 ---------------------- README.md | 2 +- backend/package-lock.json | 4 +- backend/package.json | 2 +- package-lock.json | 4 +- package.json | 2 +- scripts/next-version.sh | 28 ---------- 11 files changed, 85 insertions(+), 163 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/pr-title.yml delete mode 100644 CONTRIBUTING.md delete mode 100755 scripts/next-version.sh diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 084cd98..bfcb322 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,9 +1,6 @@ - - ## What and why ## How it was tested - [ ] `npm test` passes in the root and in `backend/` - [ ] The README is updated if behavior or the API changed -- [ ] A breaking change is marked with `!` in the title and described above diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..5aa9ca3 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,31 @@ + +name: Build and test + +on: + pull_request: + push: + +permissions: + contents: read + +jobs: + verify: + runs-on: ubuntu-latest + strategy: + matrix: + dir: [., backend] + defaults: + run: + working-directory: ${{ matrix.dir }} + steps: + - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 + + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 + with: + node-version: 20 + cache: npm + cache-dependency-path: ${{ matrix.dir }}/package-lock.json + + - run: npm ci + - run: npm test + - run: npm run build diff --git a/.github/workflows/pr-title.yml b/.github/workflows/pr-title.yml deleted file mode 100644 index 922a527..0000000 --- a/.github/workflows/pr-title.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: PR title - -on: - pull_request: - types: [opened, edited, synchronize, reopened] - -permissions: {} - -jobs: - title: - runs-on: ubuntu-latest - steps: - - name: Require a Conventional Commits title - env: - TITLE: ${{ github.event.pull_request.title }} - run: | - pattern='^(feat|fix|perf|revert|docs|chore|ci|test|refactor|style|build)(\([a-z0-9-]+\))?!?: [^ ].*' - if [[ ! "$TITLE" =~ $pattern ]]; then - echo "::error::PR title must look like 'type(scope): summary'. See CONTRIBUTING.md." - exit 1 - fi diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 467d4d3..82f1ed6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,73 +1,78 @@ -name: Build and release +name: Release on: - pull_request: push: - branches: [main] + tags: + - 'v*' permissions: contents: read jobs: - verify: - runs-on: ubuntu-latest - strategy: - matrix: - dir: [., backend] - defaults: - run: - working-directory: ${{ matrix.dir }} - steps: - - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 - - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 - with: - node-version: 20 - cache: npm - cache-dependency-path: ${{ matrix.dir }}/package-lock.json - - run: npm ci - - run: npm test - - run: npm run build - release: - if: github.event_name == 'push' - needs: verify runs-on: ubuntu-latest permissions: contents: write - id-token: write concurrency: - group: release + group: release-${{ github.ref }} env: GH_TOKEN: ${{ github.token }} steps: - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 - with: - fetch-depth: 0 + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 with: node-version: 24 registry-url: https://registry.npmjs.org - - name: Publish both packages and tag the release + + - name: Get release version from tag + id: version run: | - version=$(scripts/next-version.sh) - if [ -z "$version" ]; then - echo "Nothing to release since the last tag" - exit 0 + tag="${GITHUB_REF_NAME}" + version="${tag#v}" + + if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "::error::Invalid release tag: $tag. Expected vX.Y.Z." + exit 1 fi + + echo "version=$version" >> "$GITHUB_OUTPUT" + echo "Releasing version $version" + + - name: Publish both packages + env: + VERSION: ${{ steps.version.outputs.version }} + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + run: | for dir in . backend; do - name=$(npm pkg get name --prefix "$dir" | tr -d '"') - if npm view "$name@$version" version >/dev/null 2>&1; then - continue - fi ( cd "$dir" + + name=$(npm pkg get name | tr -d '"') + + if npm view "$name@$VERSION" version >/dev/null 2>&1; then + echo "$name@$VERSION already published, skipping" + exit 0 + fi + npm ci + npm version "$VERSION" --no-git-tag-version + npm pkg set main=dist/index.js types=dist/index.d.ts npm run build - npm pkg set version="$version" main=dist/index.js types=dist/index.d.ts npm publish ) done - git tag "v$version" - git push origin "v$version" - (cd backend && npm ci && npm run openapi:generate -- "$version") - gh release create "v$version" backend/dist/openapi.yaml --generate-notes --verify-tag + + - name: Generate OpenAPI specification + env: + VERSION: ${{ steps.version.outputs.version }} + run: | + cd backend + npm ci + npm run openapi:generate -- "$VERSION" + + - name: Create GitHub release + run: | + gh release create "$GITHUB_REF_NAME" backend/dist/openapi.yaml \ + --generate-notes \ + --verify-tag diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index bcc3974..0000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,62 +0,0 @@ -# Contributing - -## Pull request titles - -Pull requests are squash-merged, so the PR title becomes the commit message on -`main` and decides whether a release is published. Titles follow -[Conventional Commits](https://www.conventionalcommits.org/): - -``` -type(scope): summary -``` - -The scope is optional, the summary is lowercase and in the imperative mood, and -a CI check rejects anything that does not match. - -| Type | Use it for | Release | -| --- | --- | --- | -| `feat` | A new capability for users or adapters | minor | -| `fix` | A bug fix | patch | -| `perf` | A performance improvement | patch | -| `revert` | Reverting an earlier change | patch | -| `docs` | Documentation only | none | -| `refactor` | A change that alters no behavior | none | -| `test` | Tests only | none | -| `build` | Build or dependency changes | none | -| `ci` | Workflow changes | none | -| `style` | Formatting only | none | -| `chore` | Anything else | none | - -Add `!` after the type or scope for a breaking change, as in -`feat(backend)!: rename the fulfillments route`, and describe what breaks in the -PR body. A breaking change releases a new major version whatever its type. - -Examples: `fix: ignore profiles without a workload uri`, -`feat(backend): accept resource labels`, `docs: explain trusted publishing`. - -## Releases - -Merging a `feat`, `fix`, `perf`, `revert`, or breaking change to `main` -publishes both packages to npm at the next version and tags it `vX.Y.Z`; other -types release nothing, and several merges can share one release. The version is -chosen from the commit messages since the last tag. Both packages always share -a version. - -## Local checks - -``` -npm ci && npm test && npm run build -(cd backend && npm ci && npm test && npm run build) -``` - -## Maintainer setup - -- Merge with "Squash and merge", using the PR title as the commit message, and - require the `PR title` and `verify` checks on `main`. -- Publishing uses npm trusted publishing, so there is no token. For each - package, on npmjs.com open Settings, Trusted Publisher, GitHub Actions, and - enter organization `runtimeconditions`, repository `backstage-plugin`, and - workflow `release.yml`. A package must exist before it can be configured, so - publish the current version of each once by hand with - `npm publish --access public`; the first automated release then tags it - without publishing it again. diff --git a/README.md b/README.md index cae4366..09a0cf1 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ Part of the Runtime Conditions org, https://github.com/runtimeconditions: ## Contributing -See [CONTRIBUTING.md](CONTRIBUTING.md). +See the [Runtime Conditions organization contributing guidelines](https://github.com/runtimeconditions/.github/blob/main/CONTRIBUTING.md). ## License diff --git a/backend/package-lock.json b/backend/package-lock.json index 53b7a0b..5027213 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -1,12 +1,12 @@ { "name": "@runtimeconditions/plugin-runtime-conditions-backend", - "version": "0.1.0", + "version": "0.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@runtimeconditions/plugin-runtime-conditions-backend", - "version": "0.1.0", + "version": "0.0.0", "license": "MIT", "dependencies": { "@asteasolutions/zod-to-openapi": "^9.1.0", diff --git a/backend/package.json b/backend/package.json index 2fb5b3f..f37a218 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "@runtimeconditions/plugin-runtime-conditions-backend", - "version": "0.1.0", + "version": "0.0.0", "license": "MIT", "repository": { "type": "git", diff --git a/package-lock.json b/package-lock.json index 34b4482..8f7067a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@runtimeconditions/plugin-runtime-conditions", - "version": "0.1.0", + "version": "0.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@runtimeconditions/plugin-runtime-conditions", - "version": "0.1.0", + "version": "0.0.0", "dependencies": { "@backstage/catalog-model": "^1.4.0", "@backstage/core-components": "^0.14.0", diff --git a/package.json b/package.json index 98a0a0f..8be3ac9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@runtimeconditions/plugin-runtime-conditions", - "version": "0.1.0", + "version": "0.0.0", "license": "MIT", "repository": { "type": "git", diff --git a/scripts/next-version.sh b/scripts/next-version.sh deleted file mode 100755 index 487384e..0000000 --- a/scripts/next-version.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail -last=$(git describe --tags --abbrev=0 --match 'v[0-9]*.[0-9]*.[0-9]*' 2>/dev/null || true) -if [ -n "$last" ]; then - [ "$(git rev-parse "$last^{commit}")" = "$(git rev-parse HEAD)" ] && exit 0 - log=$(git log --format=%B "$last..HEAD") -else - log=$(git log --format=%B) -fi -if grep -Eq '^([a-z]+(\([^)]*\))?!:|BREAKING CHANGE)' <<<"$log"; then - bump=major -elif grep -Eq '^feat(\([^)]*\))?:' <<<"$log"; then - bump=minor -elif grep -Eq '^(fix|perf|revert)(\([^)]*\))?:' <<<"$log"; then - bump=patch -else - exit 0 -fi -if [ -z "$last" ]; then - node -p "require('./package.json').version" - exit -fi -IFS=. read -r major minor patch <<<"${last#v}" -case $bump in - major) echo "$((major + 1)).0.0" ;; - minor) echo "$major.$((minor + 1)).0" ;; - patch) echo "$major.$minor.$((patch + 1))" ;; -esac