-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
|
||
| 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 }} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 20 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}`) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.