-
Notifications
You must be signed in to change notification settings - Fork 34
Add common GitHub Actions recipes #206
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
Open
willbarton
wants to merge
6
commits into
main
Choose a base branch
from
github-actions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
88b9db0
Add common GitHub Actions recipes
willbarton 3fc4f8c
Correct typo in guides/github-actions.md
willbarton 83e2c0e
Update README.md
willbarton 53472f6
Update guides/github-actions.md
willbarton b5c9538
Update GitHub actions documentation with templates
willbarton d5b4313
Update guides/github-actions.md
willbarton 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,75 @@ | ||
| # GitHub Actions recipes | ||
|
|
||
| We use [GitHub Actions](https://github.com/features/actions) for some of our contionuous integration and other automations. | ||
|
|
||
| This guide provides some common step recipes that may be useful in custom actions. We also have a collection of common [workflow templates](https://github.com/cfpb/.github) for CI and release that make use of these steps. | ||
|
|
||
| ## Workflow templates | ||
|
|
||
| Our [workflow templates](https://github.com/cfpb/.github) provide common recipes for consumerfinance.gov-specific apps as well as our more general-purpose libraries. | ||
|
|
||
| To use our workflow templates, click on the "Actions" tab in a CFPB GitHub repository. If the repository does not already have a GitHub Actions workflow, you will be presented with the option of creating one from one of our templates: | ||
|
|
||
|  | ||
|
|
||
| If the repository already has a GitHub Actions workflow, click on the "New workflow" button at the top of the workflow list on the left. | ||
|
|
||
|  | ||
|
|
||
| Then you will be presented with the option to create one from one of our templates, shown above. | ||
|
|
||
| New workflow templates can be created in [github.com/cfpb/.github](https://github.com/cfpb/.github) based on [GitHub's workflow template documentation](https://docs.github.com/en/actions/configuring-and-managing-workflows/sharing-workflow-templates-within-your-organization). | ||
|
|
||
| ## Common step recipes | ||
|
|
||
| ### Fetching git history for setuptools-git-version | ||
|
|
||
| Some of our consumerfinance.gov satellite apps use [setuptools-git-version](https://github.com/pyfidelity/setuptools-git-version) to set the Python package version from the latest git tag. This requires tags to be available in the checkout in the GitHub action: | ||
|
|
||
| ```yml | ||
| steps: | ||
| - uses: actions/checkout@v2 | ||
|
|
||
| - name: Fetch tags and commits needed for setuptools-git-version | ||
| run: | | ||
| git fetch --depth=1 origin +refs/tags/*:refs/tags/* | ||
| git fetch origin ${{ github.head_ref }} && git checkout ${{ github.head_ref }} | ||
| ``` | ||
|
|
||
| The intention is for the command `git describe --tags --long --dirty` to succeed. If it does not, the resulting wheel filename will contain an unpredictable string that will break our common wheel file URL patterns in requirements files. | ||
|
|
||
| ## Attaching a Python wheel file to a GitHub release | ||
|
|
||
| Some of our consumerfinance.gov satellite apps have a Python wheel package file attached to their GitHub releases. We do it by outputting the wheel file name from the build step and then reading it in the upload step: | ||
|
|
||
| ```yml | ||
| steps: | ||
| - name: Build the Python packages | ||
| id: build | ||
| run: | | ||
| python setup.py sdist bdist_wheel | ||
Scotchester marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Get the name of the .whl and .tar.gz files and set them as | ||
| # "outputs" of this step so we can upload them | ||
| echo "::set-output name=bdist_wheel::$(cd dist && ls *.whl)" | ||
| echo "::set-output name=sdist::$(cd dist && ls *.tar.gz)" | ||
Scotchester marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| - name: Upload the wheel | ||
| uses: actions/upload-release-asset@v1 | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| with: | ||
| upload_url: ${{ github.event.release.upload_url }} | ||
|
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. Is it worth noting in this example that it depends on the
Member
Author
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. Yes indeed. |
||
| asset_path: dist/${{ steps.build.outputs.bdist_wheel }} | ||
| asset_name: ${{ steps.build.outputs.bdist_wheel }} | ||
| asset_content_type: application/zip | ||
|
|
||
| - name: Upload the source distribution | ||
| uses: actions/upload-release-asset@v1 | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| with: | ||
| upload_url: ${{ github.event.release.upload_url }} | ||
| asset_path: dist/${{ steps.build.outputs.sdist }} | ||
| asset_name: ${{ steps.build.outputs.sdist }} | ||
| asset_content_type: application/gzip | ||
Scotchester marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ``` | ||
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.
Could we document using the Python cache to speed up the build? I don't think we're actually using this yet on cfgov-refresh and its associated packages, but it'd be nice to do so.
We do have an example of using Node and Ruby caches on a design-system action.
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.
Yeah, I'm interested in this idea, too.
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.
Oh my goodness yes. I'll play with this and then get it integrated.