diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..40bfd38 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,59 @@ +name: Release + +on: + merge_group: + branches: + - main + push: + branches: + - main + workflow_dispatch: + +# Needed for semantic-release to create GitHub releases and publish to npm via OIDC +permissions: + contents: write + issues: write + pull-requests: write + id-token: write + +concurrency: + group: Release + cancel-in-progress: false + +jobs: + release: + name: Release + environment: Release + # Ensure releases run only when code reaches main via GitHub Merge Queue, or when manually dispatched + runs-on: ubuntu-latest + if: github.repository == 'HarperFast/nextjs' || github.repository == 'harperfast/nextjs' + steps: + - name: Checkout + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + with: + fetch-depth: 0 + - name: Setup Node.js + uses: actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38 # v6.5.0 + with: + node-version-file: '.nvmrc' + cache: npm + registry-url: 'https://registry.npmjs.org' + - name: Install dependencies + run: npm ci + # Compile the plugin so a broken build fails the release before it publishes. `dist/` is gitignored + # and rebuilt on publish via the `prepublishOnly` script, so this also surfaces build errors early. + - name: Build + run: npm run build + - name: Semantic Release + if: ${{ github.event_name == 'push' || github.event_name == 'workflow_dispatch' || (github.event_name == 'merge_group' && github.event.merge_group.base_ref == 'refs/heads/main') }} + uses: cycjimmy/semantic-release-action@b12c8f6015dc215fe37bc154d4ad456dd3833c90 # v6.0.0 + with: + extra_plugins: | + @semantic-release/commit-analyzer + @semantic-release/release-notes-generator + @semantic-release/npm + @semantic-release/git + @semantic-release/github + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_CONFIG_PROVENANCE: true diff --git a/.github/workflows/verify-commits.yaml b/.github/workflows/verify-commits.yaml new file mode 100644 index 0000000..eff4609 --- /dev/null +++ b/.github/workflows/verify-commits.yaml @@ -0,0 +1,20 @@ +name: Verify Commits + +on: + pull_request: + types: [opened, synchronize, edited, reopened, ready_for_review] + push: + branches: [main] + +jobs: + commitlint: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 + with: + fetch-depth: 0 + - name: Commitlint + uses: wagoid/commitlint-github-action@b948419dd99f3fd78a6548d48f94e3df7f6bf3ed # v6.2.1 + with: + configFile: commitlint.config.cjs diff --git a/.releaserc.json b/.releaserc.json new file mode 100644 index 0000000..43ff8b4 --- /dev/null +++ b/.releaserc.json @@ -0,0 +1,33 @@ +{ + "branches": ["main"], + "plugins": [ + "@semantic-release/commit-analyzer", + [ + "@semantic-release/release-notes-generator", + { + "preset": "conventionalcommits", + "presetConfig": { + "types": [ + { "type": "feat", "section": "Features" }, + { "type": "docs", "section": "Documentation" }, + { "type": "fix", "section": "Bug Fixes" }, + { "type": "perf", "section": "Performance Improvements" }, + { "type": "refactor", "section": "Code Improvements" }, + { "type": "revert", "section": "Reverts" }, + { "type": "test", "section": "Test Improvements" }, + { "type": "chore", "scope": "deps", "section": "Dependency Updates" } + ] + } + } + ], + "@semantic-release/npm", + [ + "@semantic-release/git", + { + "assets": ["package.json", "package-lock.json"], + "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" + } + ], + "@semantic-release/github" + ] +} diff --git a/commitlint.config.cjs b/commitlint.config.cjs new file mode 100644 index 0000000..0327923 --- /dev/null +++ b/commitlint.config.cjs @@ -0,0 +1,8 @@ +module.exports = { + extends: ['@commitlint/config-conventional'], + rules: { + 'subject-case': [0, 'never'], + 'body-max-line-length': [0, 'never'], + 'footer-max-line-length': [0, 'never'], + }, +}; diff --git a/package.json b/package.json index f199c0e..2f5d3c7 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,9 @@ "url": "git+https://github.com/HarperFast/nextjs.git" }, "license": "Apache-2.0", + "publishConfig": { + "access": "public" + }, "files": [ "dist/**", "!dist/**/*.test.*", @@ -40,7 +43,8 @@ "build": "tsc -p tsconfig.build.json", "install:fixtures": "node scripts/install-fixtures.js", "test": "npm run build && node --test \"dist/**/*.test.js\"", - "test:integration": "playwright test --config integrationTests/playwright.config.ts" + "test:integration": "playwright test --config integrationTests/playwright.config.ts", + "prepublishOnly": "npm run build" }, "engines": { "node": ">=20"