From b3d742cf07650f0d79666ea642056be1f4ff1958 Mon Sep 17 00:00:00 2001 From: Samuel Salazar Date: Tue, 10 Feb 2026 14:57:06 -0500 Subject: [PATCH] feat: add semantic-release automation --- .github/workflows/commitlint.yml | 25 ++++++++++ .github/workflows/prepare-release.yml | 70 +++++++++++++++++++++++++++ .github/workflows/release.yml | 39 +++++++++++++++ .github/workflows/test.yml | 34 +++++++++++++ .husky/commit-msg | 1 + .releaserc.json | 23 +++++++++ .travis.yml | 4 -- package.json | 18 +++---- 8 files changed, 199 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/commitlint.yml create mode 100644 .github/workflows/prepare-release.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test.yml create mode 100755 .husky/commit-msg create mode 100644 .releaserc.json delete mode 100644 .travis.yml diff --git a/.github/workflows/commitlint.yml b/.github/workflows/commitlint.yml new file mode 100644 index 0000000..7e4c1a5 --- /dev/null +++ b/.github/workflows/commitlint.yml @@ -0,0 +1,25 @@ +name: Lint Commits + +on: + pull_request: + +jobs: + commitlint: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Setup Node.js + uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0 + with: + node-version: '24' + + - name: Install dependencies + run: npm install + + - name: Validate commit messages + run: npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose diff --git a/.github/workflows/prepare-release.yml b/.github/workflows/prepare-release.yml new file mode 100644 index 0000000..4166622 --- /dev/null +++ b/.github/workflows/prepare-release.yml @@ -0,0 +1,70 @@ +name: Prepare Release + +on: + push: + branches: + - master + +concurrency: + group: prepare-release + cancel-in-progress: true + +permissions: + contents: write + pull-requests: write + +jobs: + prepare: + runs-on: ubuntu-latest + if: "!startsWith(github.event.head_commit.message, 'chore(release):')" + steps: + - name: Checkout code + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Setup Node.js + uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0 + with: + node-version: '24' + + - name: Install dependencies + run: npm install + + - name: Detect Next Version + id: version + run: | + # Run semantic-release with only commit analyzer to detect version + NEXT_VERSION=$(npx semantic-release --dry-run --plugins @semantic-release/commit-analyzer | tee /dev/stderr | awk '/The next release version is/{print $NF}') + echo "next=$NEXT_VERSION" >> $GITHUB_OUTPUT + + - name: Update package.json + if: steps.version.outputs.next != '' + run: npm version "$NEXT_VERSION" --no-git-tag-version + env: + NEXT_VERSION: ${{ steps.version.outputs.next }} + + - name: Update CHANGELOG.md + if: steps.version.outputs.next != '' + run: npx conventional-changelog-cli -p angular -i CHANGELOG.md -s + + - name: Create Pull Request + if: steps.version.outputs.next != '' + uses: peter-evans/create-pull-request@c0f553fe549906ede9cf27b5156039d195d2ece0 # v8.1.0 + with: + token: ${{ secrets.GITHUB_TOKEN }} + commit-message: "chore(release): ${{ steps.version.outputs.next }}" + branch: "release/v${{ steps.version.outputs.next }}" + delete-branch: true + title: "chore(release): ${{ steps.version.outputs.next }}" + body: | + This PR prepares the release of version ${{ steps.version.outputs.next }}. + + **Changes:** + - Updated version in `package.json` to ${{ steps.version.outputs.next }} + - Updated `CHANGELOG.md` with release notes + + **Next Steps:** + Review and merge this PR to trigger the publish workflow. + labels: release diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..8683969 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,39 @@ +name: Release + +on: + push: + branches: + - master + +permissions: + contents: write + issues: write + pull-requests: write + id-token: write + +jobs: + release: + runs-on: ubuntu-latest + environment: release + if: startsWith(github.event.head_commit.message, 'chore(release):') + + steps: + - name: Checkout code + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Setup Node.js + uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0 + with: + node-version: '24' + + - name: Install dependencies + run: npm install + + - name: Release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_CONFIG_PROVENANCE: true + run: npx semantic-release diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..70597c0 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,34 @@ +name: Test + +on: + pull_request: + types: [opened, synchronize] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + node-version: ['20', '22', '24'] + + steps: + - name: Checkout code + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 + with: + persist-credentials: false + + - name: Setup Node.js ${{ matrix.node-version }} + uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0 + with: + node-version: ${{ matrix.node-version }} + + - name: Install dependencies + run: npm install + + - name: Test + run: npm test diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100755 index 0000000..0a4b97d --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1 @@ +npx --no -- commitlint --edit $1 diff --git a/.releaserc.json b/.releaserc.json new file mode 100644 index 0000000..be2c71d --- /dev/null +++ b/.releaserc.json @@ -0,0 +1,23 @@ +{ + "branches": [ + "master" + ], + "plugins": [ + "@semantic-release/commit-analyzer", + "@semantic-release/release-notes-generator", + [ + "@semantic-release/npm", + { + "npmPublish": true, + "pkgRoot": "." + } + ], + [ + "@semantic-release/exec", + { + "prepareCmd": "git diff --exit-code -- package.json" + } + ], + "@semantic-release/github" + ] +} diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 521fe8e..0000000 --- a/.travis.yml +++ /dev/null @@ -1,4 +0,0 @@ -language: node_js -node_js: - - 10.16.0 - - 12.10.0 diff --git a/package.json b/package.json index 5255318..df0b9b7 100644 --- a/package.json +++ b/package.json @@ -5,13 +5,14 @@ "node": ">=12" }, "devDependencies": { - "@commitlint/cli": "^11.0.0", - "@commitlint/config-conventional": "^11.0.0", + "@commitlint/cli": "^20.3.1", + "@commitlint/config-conventional": "^20.3.1", + "@semantic-release/exec": "^7.0.3", "chai": "^4.2.0", - "husky": "^4.3.0", + "husky": "^9.1.7", "mocha": "^8.2.0", - "should": "~1.2.1", - "standard-version": "^9.0.0" + "semantic-release": "^25.0.2", + "should": "~1.2.1" }, "main": "./lib", "repository": "https://github.com/auth0/node-saml", @@ -32,12 +33,7 @@ "xpath": "0.0.5" }, "scripts": { - "release": "standard-version", + "prepare": "husky", "test": "mocha" - }, - "husky": { - "hooks": { - "commit-msg": "commitlint -E HUSKY_GIT_PARAMS" - } } }