-
Notifications
You must be signed in to change notification settings - Fork 1
Bring over our composite actions from Khan/perseus #3
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Changesets | ||
|
|
||
| Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works | ||
| with multi-package repos, or single-package repos to help you version and publish your code. You can | ||
| find the full documentation for it [in our repository](https://github.com/changesets/changesets) | ||
|
|
||
| We have a quick list of common questions to get you started engaging with this project in | ||
| [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) |
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,13 @@ | ||
| { | ||
| "$schema": "https://unpkg.com/@changesets/config@1.7.0/schema.json", | ||
| "changelog": "@changesets/cli/changelog", | ||
| "commit": false, | ||
| "linked": [], | ||
| "access": "public", | ||
| "baseBranch": "main", | ||
| "updateInternalDependencies": "patch", | ||
| "ignore": [], | ||
| "___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": { | ||
| "updateInternalDependents": "always" | ||
| } | ||
| } |
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,15 @@ | ||
| # @Khan/actions | ||
|
|
||
| A monorepo for shared github actions. | ||
|
|
||
| Currently only composite actions are supported, although supporting nodejs actions probably wouldn't be too hard. If your script is simple, you can do a composite action that uses `actions/github-script`, see the `filter-files` action for an example. | ||
|
|
||
| ## How does the monorepo work? | ||
|
|
||
| Github doesn't support putting actions in subdirectories, so we need to do some fancy work here. Inspired by [gitpkg](https://github.com/ramasilveyra/gitpkg), we "publish" versions of our actions to 'bare tags' in this repo. So the tag `filter-files-v0.0.1` would only contain the files for the `filter-files` action, and thus github is perfectly happy for us to reference it as `uses: @Khan/actions#filter-files-v0.0.1`. | ||
|
|
||
| Actions that depend on other actions within this repo (with e.g. `uses: filter-files`) will have the references automatically converted to the appropriated pinned reference (e.g. `Khan/actions#filter-files-v0.0.1`) as part of the publish process. | ||
|
|
||
| ## How does changeset play in? | ||
|
|
||
| Changeset helps us track what needs to be published, and automatically produces a changelog so we know what changed in a given release. |
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,27 @@ | ||
| name: 'Check for a changeset' | ||
| description: 'Fail if no .changeset/*.md file is included in the PR.' | ||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - name: "Get All Changed Files" | ||
| id: changed | ||
| uses: jaredly/get-changed-files@v1.0.1 | ||
| with: | ||
| format: json | ||
| - uses: actions/github-script@v6 | ||
| with: | ||
| script: | | ||
| const inputFiles = JSON.parse(`${{ steps.changed.outputs.added_modified }}`); | ||
| core.debug("Changed files: " + inputFiles); | ||
|
|
||
| const hasChangeset = inputFiles.some(name => { | ||
| return /^\.changeset\/.*\.md/.test(name); | ||
| }); | ||
| if (!hasChangeset) { | ||
| core.setFailed( | ||
| "This PR does not have a changeset. You can add one by " + | ||
| "running `yarn changeset` and following the prompts.\n" + | ||
| "If this PR doesn't need a changeset, run `yarn changeset " + | ||
| "--empty` and commit results." | ||
| ); | ||
| } |
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,4 @@ | ||
| { | ||
| "name": "check-for-changeset", | ||
| "version": "0.0.0" | ||
| } |
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,37 @@ | ||
| name: 'Filter files please' | ||
| description: 'Filter the list of changed files' | ||
| inputs: | ||
| changed-files: | ||
| description: 'jsonified list of changed files from setup' | ||
| required: true | ||
| files: | ||
| description: 'comma-separated list of files to check for' | ||
| required: false | ||
| extensions: | ||
| description: 'comma-separated list of extensions to check for' | ||
| required: false | ||
| outputs: | ||
| filtered: | ||
| description: 'The jsonified list of files that match' | ||
| value: ${{ steps.result.outputs.result }} | ||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - uses: actions/github-script@v6 | ||
| id: result | ||
| with: | ||
| script: | | ||
| const extensionsRaw = "${{ inputs.extensions }}"; | ||
| const exactFilesRaw = "${{ inputs.files }}"; | ||
| const inputFiles = JSON.parse(`${{ inputs.changed-files }}`); | ||
| const extensions = extensionsRaw.trim() ? extensionsRaw.split(',') : []; | ||
| const exactFiles = exactFilesRaw.trim() ? exactFilesRaw.split(',') : []; | ||
|
|
||
| const result = inputFiles.filter(name => { | ||
| return extensions.some(ext => name.endsWith(ext)) || ( | ||
| exactFiles.includes(name) | ||
| ) | ||
| }) | ||
| console.log(`Filtered Files: ${JSON.stringify(result)}`) | ||
| return result; | ||
| result-encoding: json | ||
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,4 @@ | ||
| { | ||
| "name": "filter-files", | ||
| "version": "0.0.0" | ||
| } |
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,28 @@ | ||
| name: Full or Limited | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for abstracting this into an action. |
||
| description: Do a full run if certain files have changed, or a limited run of some others have changed | ||
| inputs: | ||
| full-trigger: | ||
| description: A jsonified Array of string files that would trigger a full run | ||
| required: true | ||
| limited-trigger: | ||
| description: A jsonified Array of string files that should be passed to a limited run | ||
| required: true | ||
| full: | ||
| description: The command to run if a full run is triggered | ||
| limited: | ||
| description: The command to run, with {} replaced with the list of files to run on. | ||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - name: Full run | ||
| if: inputs.full-trigger != '[]' | ||
| run: ${{ inputs.full }} | ||
| shell: bash | ||
|
|
||
| - name: Limited run | ||
| if: inputs.full-trigger == '[]' && inputs.limited-trigger != '[]' | ||
| # Will be replaced with a pinned version by our build system | ||
| uses: json-args | ||
| with: | ||
| list: ${{ inputs.limited-trigger }} | ||
| run: ${{ inputs.limited }} | ||
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,7 @@ | ||
| { | ||
| "name": "full-or-limited", | ||
| "version": "0.0.0", | ||
| "dependencies": { | ||
| "json-args": "*" | ||
| } | ||
| } |
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,32 @@ | ||
| name: 'Pass a jsonified-list of files as shell arguments yes' | ||
| description: 'Because file names with spaces are the worst' | ||
| inputs: | ||
| list: | ||
| description: A jsonified Array of string file names | ||
| required: true | ||
| run: | ||
| description: "a command to run, where the literal '{}' will be replaced with the files as individual arguments. If no '{}' is provided, the files will be appended." | ||
| required: true | ||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - uses: actions/github-script@v6 | ||
| with: | ||
| script: | | ||
| const listRaw = `${{ inputs.list }}`; | ||
| const files = JSON.parse(listRaw); | ||
| const {execSync} = require('child_process'); | ||
| if (files.some(name => name.match(/['"]/))) { | ||
| throw new Error(`Not going to mess with file names that have quotes in them.`) | ||
| } | ||
| const filesList = files.map(name => `"${name}"`).join(' ') | ||
| let cmd = `${{ inputs.run }}`; | ||
| if (cmd.includes('{}')) { | ||
| cmd = cmd.replace('{}', filesList) | ||
| } else { | ||
| cmd += ' ' + filesList; | ||
| } | ||
| console.log(`Running: ${cmd}`); | ||
| execSync(cmd, { | ||
| stdio: 'inherit', | ||
| }) |
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,4 @@ | ||
| { | ||
| "name": "json-args", | ||
| "version": "0.0.3" | ||
| } |
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,29 @@ | ||
| name: 'Shared Node Cache' | ||
| description: 'Install & cache our npm dependencies' | ||
| inputs: | ||
| node-version: | ||
| description: 'Node version to use' | ||
| required: false | ||
| default: '16.x' | ||
| runs: | ||
| using: "composite" | ||
| steps: | ||
|
|
||
| - name: Use Node.js ${{ inputs.node-version }} | ||
| uses: actions/setup-node@v2 | ||
| with: | ||
| node-version: ${{ inputs.node-version }} | ||
|
|
||
| - name: Cache node_modules | ||
| uses: actions/cache@v2 | ||
| id: cache-node-modules | ||
| with: | ||
| path: node_modules | ||
| key: ${{ runner.os }}-${{ inputs.node-version }}-node_modules-${{ hashFiles('**/yarn.lock') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-${{ inputs.node-version }}-node_modules- | ||
|
|
||
| - name: Install Dependencies | ||
| if: steps.cache-node-modules.outputs.cache-hit != 'true' | ||
| shell: bash | ||
| run: yarn install --frozen-lockfile |
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,4 @@ | ||
| { | ||
| "name": "shared-node-cache", | ||
| "version": "0.0.2" | ||
| } |
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,10 @@ | ||
| { | ||
| "repository": "git@github.com:Khan/actions.git", | ||
| "private": true, | ||
| "workspaces": [ | ||
| "actions/*" | ||
| ], | ||
| "devDependencies": { | ||
| "@changesets/cli": "^2.22.0" | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should have a policy (in a future change) of breaking out inline scripts to be imported from another file? That way we can lint and test them, for example: https://github.com/actions/github-script#run-a-separate-file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on interesting, I didn't know that was an option! Sounds like a good policy.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jeresig has that always been possible or is this a new feature? Either way, I'm glad it's possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always been possible, I believe!