diff --git a/.github/workflows/changesets-version.yml b/.github/workflows/changesets-version.yml deleted file mode 100644 index f9ba8bd..0000000 --- a/.github/workflows/changesets-version.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Version Packages - -on: - push: - branches: [ main ] - -permissions: - contents: write - pull-requests: write - -jobs: - version: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - uses: actions/setup-node@v4 - with: - node-version: '24' - cache: 'npm' - - - name: Install dependencies - run: npm ci - - - name: Create or update version PR - uses: changesets/action@v1 - with: - version: npm run version-packages - commit: "chore: version packages" - title: "chore: version packages" - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - diff --git a/.github/workflows/main.yml b/.github/workflows/ci.yml similarity index 95% rename from .github/workflows/main.yml rename to .github/workflows/ci.yml index 5007f53..f61299d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: Build and Test +name: CI on: push: @@ -14,7 +14,7 @@ permissions: id-token: write jobs: - build: + build-and-test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..9159a55 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,126 @@ +name: Release + +on: + push: + branches: [ main ] + pull_request: + types: [opened, synchronize, labeled] + +permissions: + contents: write + pull-requests: write + +jobs: + version-packages: + runs-on: ubuntu-latest + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: actions/setup-node@v4 + with: + node-version: '24' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Create or update version PR + uses: changesets/action@v1 + with: + version: npm run version-packages + commit: "chore: version packages" + title: "chore: version packages" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + auto-merge-version: + runs-on: ubuntu-latest + if: | + github.event_name == 'pull_request' && + github.event.pull_request.title == 'chore: version packages' && + github.event.pull_request.head.repo.full_name == github.repository && + (github.event.action == 'opened' || github.event.action == 'synchronize' || (github.event.action == 'labeled' && github.event.label.name == 'auto-merge')) + steps: + - name: Wait for status checks + uses: actions/github-script@v7 + id: wait + with: + script: | + const maxWait = 300; // 5 minutes + const checkInterval = 10; // 10 seconds + let waited = 0; + + while (waited < maxWait) { + const { data: pr } = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.payload.pull_request.number, + }); + + if (pr.mergeable === true && pr.mergeable_state === 'clean') { + console.log('PR is ready to merge'); + return; + } + + console.log(`Waiting for checks... (${waited}s)`); + await new Promise(resolve => setTimeout(resolve, checkInterval * 1000)); + waited += checkInterval; + } + + throw new Error('Timeout waiting for PR to be mergeable'); + + - name: Auto-merge version PR + uses: actions/github-script@v7 + with: + script: | + await github.rest.pulls.merge({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: context.payload.pull_request.number, + merge_method: 'squash' + }); + + tag-on-version: + runs-on: ubuntu-latest + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + steps: + - name: Check if version commit + id: check + run: | + if [[ "${{ github.event.head_commit.message }}" == *"chore: version packages"* ]]; then + echo "is_version=true" >> $GITHUB_OUTPUT + else + echo "is_version=false" >> $GITHUB_OUTPUT + fi + + - uses: actions/checkout@v4 + if: steps.check.outputs.is_version == 'true' + with: + fetch-depth: 0 + + - uses: actions/setup-node@v4 + if: steps.check.outputs.is_version == 'true' + with: + node-version: '24' + cache: 'npm' + + - name: Install dependencies + if: steps.check.outputs.is_version == 'true' + run: npm ci + + - name: Create tags from Changesets + if: steps.check.outputs.is_version == 'true' + run: npx changeset tag + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Push tags + if: steps.check.outputs.is_version == 'true' + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git push --follow-tags + diff --git a/.github/workflows/tag-on-version.yml b/.github/workflows/tag-on-version.yml deleted file mode 100644 index 7976fc9..0000000 --- a/.github/workflows/tag-on-version.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: Tag on Version Commit - -on: - push: - branches: [ main ] - -permissions: - contents: write - -jobs: - tag: - runs-on: ubuntu-latest - steps: - - name: Check if version commit - id: check - run: | - if [[ "${{ github.event.head_commit.message }}" == *"chore: version packages"* ]]; then - echo "is_version=true" >> $GITHUB_OUTPUT - else - echo "is_version=false" >> $GITHUB_OUTPUT - fi - - - uses: actions/checkout@v4 - if: steps.check.outputs.is_version == 'true' - with: - fetch-depth: 0 - - - uses: actions/setup-node@v4 - if: steps.check.outputs.is_version == 'true' - with: - node-version: '24' - cache: 'npm' - - - name: Install dependencies - if: steps.check.outputs.is_version == 'true' - run: npm ci - - - name: Create tags from Changesets - if: steps.check.outputs.is_version == 'true' - run: npx changeset tag - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Push tags - if: steps.check.outputs.is_version == 'true' - run: | - git config user.name "github-actions[bot]" - git config user.email "github-actions[bot]@users.noreply.github.com" - git push --follow-tags -