diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9ec1d08..3fa9c73 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,9 +1,6 @@ name: CI on: - push: - branches: - - main pull_request: concurrency: @@ -21,6 +18,7 @@ jobs: - uses: actions/setup-node@v4 with: + node-version: "22" cache: pnpm - run: pnpm install --frozen-lockfile diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..e2001af --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,145 @@ +name: Publish + +on: + push: + branches: + - main + workflow_dispatch: + inputs: + skip-checks: + description: "Skip checks" + type: boolean + default: false + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + check: + if: ${{ !(github.event_name == 'workflow_dispatch' && inputs.skip-checks) }} + runs-on: ubuntu-latest + timeout-minutes: 10 + steps: + - uses: actions/checkout@v4 + + - uses: pnpm/action-setup@v4 + + - uses: actions/setup-node@v4 + with: + node-version: "22" + cache: pnpm + + - run: pnpm install --frozen-lockfile + + - run: pnpm check + + - run: pnpm typecheck + + - run: pnpm test + + publish: + name: Publish + needs: check + if: ${{ always() && (needs.check.result == 'success' || needs.check.result == 'skipped') }} + runs-on: ubuntu-latest + timeout-minutes: 10 + permissions: + contents: write + packages: write + pull-requests: write + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: pnpm/action-setup@v4 + + - uses: actions/setup-node@v4 + with: + node-version: "22" + registry-url: https://npm.pkg.github.com + scope: "@aliou" + cache: pnpm + + - run: pnpm install --frozen-lockfile + + - run: pnpm build + + - name: Get release info + id: release-info + run: | + pnpm changeset status --output=release.json 2>/dev/null || echo '{"releases":[]}' > release.json + node < r.type !== 'none') || []; + + let title = 'Version Packages'; + let commit = 'Version Packages'; + if (releases.length === 1) { + const { name, newVersion } = releases[0]; + title = 'Updating ' + name + ' to version ' + newVersion; + commit = name + '@' + newVersion; + } else if (releases.length > 1) { + const summary = releases.map(r => r.name + '@' + r.newVersion).join(', '); + title = 'Updating ' + summary; + commit = summary; + } + + fs.appendFileSync(process.env.GITHUB_OUTPUT, 'title=' + title + '\n'); + fs.appendFileSync(process.env.GITHUB_OUTPUT, 'commit=' + commit + '\n'); + NODE + rm -f release.json + continue-on-error: true + + - name: Create Release PR or Publish + id: changesets + uses: changesets/action@v1 + with: + version: pnpm changeset version + publish: pnpm changeset publish + title: ${{ steps.release-info.outputs.title || 'Version Packages' }} + commit: ${{ steps.release-info.outputs.commit || 'Version Packages' }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Create GitHub releases + if: steps.changesets.outputs.published == 'true' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PUBLISHED_PACKAGES: ${{ steps.changesets.outputs.publishedPackages }} + run: | + node <<'NODE' + const { execSync } = require("node:child_process"); + + const published = JSON.parse(process.env.PUBLISHED_PACKAGES || "[]"); + + for (const pkg of published) { + const shortName = pkg.name.replace(/^@[^/]+\//, ""); + const tag = `${shortName}@${pkg.version}`; + + const existing = execSync(`git tag --list ${tag}`, { encoding: "utf8" }).trim(); + if (!existing) { + execSync(`git tag ${tag}`); + execSync(`git push origin ${tag}`); + } + + let hasRelease = false; + try { + const output = execSync(`gh release view ${tag} --json tagName --jq .tagName`, { + stdio: ["ignore", "pipe", "ignore"], + }).toString().trim(); + hasRelease = output.length > 0; + } catch { + hasRelease = false; + } + + if (!hasRelease) { + execSync(`gh release create ${tag} --title ${tag} --notes "Release ${tag}"`, { + stdio: "inherit", + }); + } + } + NODE diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 799b5cd..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,42 +0,0 @@ -name: Release - -on: - push: - branches: - - main - -concurrency: - group: release - cancel-in-progress: false - -jobs: - release: - runs-on: ubuntu-latest - timeout-minutes: 10 - permissions: - contents: write - packages: write - pull-requests: write - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - uses: pnpm/action-setup@v4 - - - uses: actions/setup-node@v4 - with: - cache: pnpm - registry-url: https://npm.pkg.github.com - - - run: pnpm install --frozen-lockfile - - - run: pnpm build - - - uses: changesets/action@v1 - with: - version: pnpm changeset version - publish: pnpm changeset publish - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}