diff --git a/.changeset/config.json b/.changeset/config.json index ec48809..65d46d4 100644 --- a/.changeset/config.json +++ b/.changeset/config.json @@ -1,10 +1,14 @@ { - "$schema": "https://unpkg.com/@changesets/config/schema.json", + "$schema": "https://unpkg.com/@changesets/config@2.3.1/schema.json", "changelog": [ "@changesets/changelog-github", { "repo": "addon-stack/storage" } ], "commit": false, + "fixed": [], + "linked": [], "access": "public", - "baseBranch": "main" + "baseBranch": "main", + "updateInternalDependencies": "patch", + "ignore": [] } diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 06786b2..c32bfea 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,6 +5,7 @@ on: branches: [develop, main] push: branches: [main] + workflow_call: {} concurrency: group: ${{ github.workflow }}-${{ github.ref || github.run_id }} diff --git a/.github/workflows/release-prepare.yml b/.github/workflows/release-prepare.yml new file mode 100644 index 0000000..dd247e5 --- /dev/null +++ b/.github/workflows/release-prepare.yml @@ -0,0 +1,67 @@ +name: Release Prepare + +on: + push: + branches: + - 'release/*' + +permissions: + contents: write + pull-requests: write + +jobs: + ci: + uses: ./.github/workflows/ci.yml + secrets: inherit + + prepare: + name: Prepare release with Changesets (version + changelog) + runs-on: ubuntu-latest + needs: ci + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: npm + + - name: Install dependencies + run: npm ci + + - name: Generate versions & changelog (changeset version) + run: npx changeset version + env: + HUSKY: 0 + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Commit version & changelog changes + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "chore: version packages (prepare release)" + commit_user_name: github-actions[bot] + commit_user_email: 41898282+github-actions[bot]@users.noreply.github.com + + - name: Open or update PR to main + uses: actions/github-script@v7 + with: + script: | + const { owner, repo } = context.repo; + const head = context.ref.replace('refs/heads/', ''); + const base = 'main'; + const title = 'chore: release (prepared by Changesets)'; + const body = 'This PR was automatically created by release-prepare workflow. It contains version bumps and CHANGELOG updates generated by Changesets.'; + + const existing = await github.rest.pulls.list({ owner, repo, state: 'open', head: `${owner}:${head}`, base }); + if (existing.data.length > 0) { + const pr = existing.data[0]; + await github.rest.pulls.update({ owner, repo, pull_number: pr.number, title, body }); + core.info(`Updated PR #${pr.number}: ${pr.html_url}`); + } else { + const pr = await github.rest.pulls.create({ owner, repo, head, base, title, body }); + core.info(`Created PR #${pr.data.number}: ${pr.data.html_url}`); + } diff --git a/.github/workflows/release.yml b/.github/workflows/release-publish.yml similarity index 61% rename from .github/workflows/release.yml rename to .github/workflows/release-publish.yml index 612290a..154a1b2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release-publish.yml @@ -1,4 +1,4 @@ -name: Release +name: Release Publish on: push: @@ -6,37 +6,39 @@ on: permissions: contents: write - id-token: write pull-requests: write + id-token: write jobs: - release: + ci: + uses: ./.github/workflows/ci.yml + secrets: inherit + + publish: + name: Publish to npm via Changesets runs-on: ubuntu-latest + needs: ci steps: - name: Checkout uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Setup Node + - name: Setup Node.js uses: actions/setup-node@v4 with: node-version: 20 - registry-url: https://registry.npmjs.org cache: npm + registry-url: https://registry.npmjs.org - - name: Install + - name: Install dependencies run: npm ci - - name: Build - run: npm run build - - name: Create Release PR or Publish to npm uses: changesets/action@v1 with: - publish: npm publish --provenance --access public + publish: npm run release createGithubReleases: true + commitMode: github-api env: - HUSKY: 0 GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + NPM_CONFIG_PROVENANCE: "true" diff --git a/CHANGELOG.md b/CHANGELOG.md index 449b103..b45f3a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,11 @@ ### Patch Changes -- [`40c75eb`](https://github.com/addon-stack/storage/commit/40c75ebeaa8960e5d7f483a84ddae24b7a347f03) Thanks [@addon-stack](https://github.com/addon-stack)! - Fix pipeline +- [`40c75eb`](https://github.com/addon-stack/storage/commit/40c75ebeaa8960e5d7f483a84ddae24b7a347f03) Thanks [@addon-stack](https://github.com/addon-stack)! - ### Configure workflows for release preparation and publishing + - Added `release-prepare.yml` to automate versioning and changelog generation with Changesets. + - Renamed and updated `release.yml` to `release-publish.yml` for npm publishing. + - Enhanced `ci.yml` workflow with support for workflow calls. + - Updated Changesets configuration and added `release` script in `package.json`. ## 0.1.1 diff --git a/package.json b/package.json index 91bde94..8a11be4 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,8 @@ "test": "jest", "test:run": "jest --ci --passWithNoTests", "test:related": "jest --bail --passWithNoTests --findRelatedTests", - "typecheck": "tsc -p tsconfig.json --noEmit" + "typecheck": "tsc -p tsconfig.json --noEmit", + "release": "changeset publish" }, "lint-staged": { "*.{ts,tsx,js,jsx}": [