Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Align release and publish automation#7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| name: Publish | ||
| on: | ||
| workflow_run: | ||
| workflows: | ||
| - CI | ||
| types: | ||
| - completed | ||
| workflow_dispatch: | ||
| inputs: | ||
| codemod_name: | ||
| description: Codemod directory name under codemods/ | ||
| required: true | ||
| type: string | ||
| concurrency: ${{ github.workflow }}-${{ github.event.workflow_run.head_branch || github.ref }} | ||
| permissions: | ||
| id-token: write | ||
| contents: write | ||
| jobs: | ||
| tag: | ||
| name: Tag released versions | ||
| if: >- | ||
| github.event.workflow_run.conclusion == 'success' && | ||
| github.event.workflow_run.event == 'push' && | ||
| github.event.workflow_run.head_branch == 'main' | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| changed_dirs: ${{ steps.tag.outputs.changed_dirs }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.event.workflow_run.head_sha }} | ||
| fetch-depth: 0 | ||
| - uses: pnpm/action-setup@f520eceda224fe1a4aed5a2a27a194379a409996 # v6 | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version-file: .nvmrc | ||
| cache: pnpm | ||
| - run: pnpm install --frozen-lockfile | ||
| - name: Detect pending changesets | ||
| id: pending | ||
| run: | | ||
| count="$(find .changeset -maxdepth 1 -type f -name '*.md' ! -name 'README.md' | wc -l | tr -d ' ')" | ||
| echo "count=$count" >> "$GITHUB_OUTPUT" | ||
| - name: Tag released versions | ||
| if: steps.pending.outputs.count == '0' | ||
| id: tag | ||
| run: node scripts/tag-and-publish.mjs | ||
| publish: | ||
| name: Publish ${{ matrix.dir }} | ||
| needs: tag | ||
| if: >- | ||
| github.event_name == 'workflow_run' && | ||
| needs.tag.outputs.changed_dirs != '' && | ||
| needs.tag.outputs.changed_dirs != '[]' | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| dir: ${{ fromJson(needs.tag.outputs.changed_dirs) }} | ||
Copilot marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.event.workflow_run.head_sha }} | ||
| - uses: pnpm/action-setup@f520eceda224fe1a4aed5a2a27a194379a409996 # v6 | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version-file: .nvmrc | ||
| cache: pnpm | ||
| - run: pnpm install --frozen-lockfile | ||
| - name: Publish codemod | ||
| uses: codemod/publish-action@dd6c8dbc5ceb1a6146feba41481d88b43da50024 # v1 | ||
| with: | ||
| path: ${{ matrix.dir }} | ||
| publish-manual: | ||
| name: Publish codemod (manual) | ||
| if: github.event_name == 'workflow_dispatch' | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - name: Publish codemod | ||
| uses: codemod/publish-action@dd6c8dbc5ceb1a6146feba41481d88b43da50024 # v1 | ||
| with: | ||
| path: codemods/${{ inputs.codemod_name }} | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 20 |
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| #!/usr/bin/env node | ||
| import { readdirSync, readFileSync, writeFileSync } from 'node:fs' | ||
| import { dirname, join, relative } from 'node:path' | ||
| import { fileURLToPath } from 'node:url' | ||
| const root = join(dirname(fileURLToPath(import.meta.url)), '..') | ||
| const versionPattern = /^version:\s*(['"]?)([^'"\n]+)\1\s*$/m | ||
| function findCodemodYamlFiles(directory) { | ||
| const paths = [] | ||
| for (const entry of readdirSync(directory, { withFileTypes: true })) { | ||
| if (entry.name === 'node_modules') continue | ||
| const path = join(directory, entry.name) | ||
| if (entry.isDirectory()) { | ||
| paths.push(...findCodemodYamlFiles(path)) | ||
| } else if (entry.isFile() && entry.name === 'codemod.yaml') { | ||
| paths.push(path) | ||
| } | ||
| } | ||
| return paths | ||
| } | ||
| for (const yamlPath of findCodemodYamlFiles(join(root, 'codemods'))) { | ||
| const dir = dirname(yamlPath) | ||
| const { version } = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8')) | ||
| const content = readFileSync(yamlPath, 'utf8') | ||
| const updated = content.replace(versionPattern, `version: "${version}"`) | ||
| if (updated !== content) { | ||
| writeFileSync(yamlPath, updated) | ||
| console.log(`${relative(root, yamlPath)} -> ${version}`) | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.