|
| 1 | +name: Publish |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: |
| 6 | + - CI |
| 7 | + types: |
| 8 | + - completed |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + codemod_name: |
| 12 | + description: Codemod directory name under codemods/ |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + |
| 16 | +concurrency: ${{ github.workflow }}-${{ github.event.workflow_run.head_branch || github.ref }} |
| 17 | + |
| 18 | +permissions: |
| 19 | + id-token: write |
| 20 | + contents: write |
| 21 | + |
| 22 | +jobs: |
| 23 | + tag: |
| 24 | + name: Tag released versions |
| 25 | + if: >- |
| 26 | + github.event.workflow_run.conclusion == 'success' && |
| 27 | + github.event.workflow_run.event == 'push' && |
| 28 | + github.event.workflow_run.head_branch == 'main' |
| 29 | + runs-on: ubuntu-latest |
| 30 | + outputs: |
| 31 | + changed_dirs: ${{ steps.tag.outputs.changed_dirs }} |
| 32 | + steps: |
| 33 | + - uses: actions/checkout@v4 |
| 34 | + with: |
| 35 | + ref: ${{ github.event.workflow_run.head_sha }} |
| 36 | + fetch-depth: 0 |
| 37 | + |
| 38 | + - uses: pnpm/action-setup@f520eceda224fe1a4aed5a2a27a194379a409996 # v6 |
| 39 | + |
| 40 | + - uses: actions/setup-node@v4 |
| 41 | + with: |
| 42 | + node-version-file: .nvmrc |
| 43 | + cache: pnpm |
| 44 | + |
| 45 | + - run: pnpm install --frozen-lockfile |
| 46 | + |
| 47 | + - name: Detect pending changesets |
| 48 | + id: pending |
| 49 | + run: | |
| 50 | + count="$(find .changeset -maxdepth 1 -type f -name '*.md' ! -name 'README.md' | wc -l | tr -d ' ')" |
| 51 | + echo "count=$count" >> "$GITHUB_OUTPUT" |
| 52 | +
|
| 53 | + - name: Tag released versions |
| 54 | + if: steps.pending.outputs.count == '0' |
| 55 | + id: tag |
| 56 | + run: node scripts/tag-and-publish.mjs |
| 57 | + |
| 58 | + publish: |
| 59 | + name: Publish ${{ matrix.dir }} |
| 60 | + needs: tag |
| 61 | + if: >- |
| 62 | + github.event_name == 'workflow_run' && |
| 63 | + needs.tag.outputs.changed_dirs != '' && |
| 64 | + needs.tag.outputs.changed_dirs != '[]' |
| 65 | + runs-on: ubuntu-latest |
| 66 | + strategy: |
| 67 | + fail-fast: false |
| 68 | + matrix: |
| 69 | + dir: ${{ fromJson(needs.tag.outputs.changed_dirs) }} |
| 70 | + steps: |
| 71 | + - uses: actions/checkout@v4 |
| 72 | + with: |
| 73 | + ref: ${{ github.event.workflow_run.head_sha }} |
| 74 | + |
| 75 | + - uses: pnpm/action-setup@f520eceda224fe1a4aed5a2a27a194379a409996 # v6 |
| 76 | + |
| 77 | + - uses: actions/setup-node@v4 |
| 78 | + with: |
| 79 | + node-version-file: .nvmrc |
| 80 | + cache: pnpm |
| 81 | + |
| 82 | + - run: pnpm install --frozen-lockfile |
| 83 | + |
| 84 | + - name: Publish codemod |
| 85 | + uses: codemod/publish-action@dd6c8dbc5ceb1a6146feba41481d88b43da50024 # v1 |
| 86 | + with: |
| 87 | + path: ${{ matrix.dir }} |
| 88 | + |
| 89 | + publish-manual: |
| 90 | + name: Publish codemod (manual) |
| 91 | + if: github.event_name == 'workflow_dispatch' |
| 92 | + runs-on: ubuntu-latest |
| 93 | + steps: |
| 94 | + - uses: actions/checkout@v4 |
| 95 | + |
| 96 | + - name: Publish codemod |
| 97 | + uses: codemod/publish-action@dd6c8dbc5ceb1a6146feba41481d88b43da50024 # v1 |
| 98 | + with: |
| 99 | + path: codemods/${{ inputs.codemod_name }} |
0 commit comments