GitHub Action
"Create Tag" Action for GitHub Actions
Use this template to bootstrap the creation of a JavaScript action.:rocket:
This template includes tests, linting, a validation workflow, publishing, and versioning guidance.
If you are new, there's also a simpler introduction. See the Hello World JavaScript Action
Click the Use this Template
and provide the new repo details for your action
Install the dependencies
npm install
Run the tests ✔️
$ npm test
PASS ./index.test.js
✓ throws invalid number (3ms)
✓ wait 500 ms (504ms)
✓ test runs (95ms)
...
The action.yml defines the inputs and output for your action.
Update the action.yml with your name, description, inputs and outputs for your action.
See the documentation
Most toolkit and CI/CD operations involve async operations so the action is run in an async function.
const core = require('@actions/core');
...
async function run() {
try {
...
}
catch (error) {
core.setFailed(error.message);
}
}
run()
See the toolkit documentation for the various packages.
GitHub Actions will run the entry point from the action.yml. Packaging assembles the code into one file that can be checked in to Git, enabling fast and reliable execution and preventing the need to check in node_modules.
Actions are run from GitHub repos. Packaging the action will create a packaged action in the dist folder.
Run prepare
npm run prepare
Since the packaged index.js is run from the dist folder.
git add dist
Users shouldn't consume the action from master since that would be latest code and actions can break compatibility between major versions.
Checkin to the v1 release branch
git checkout -b v1
git commit -a -m "v1 release"
git push origin v1
Note: We recommend using the --license
option for ncc, which will create a license file for all of the production node modules used in your project.
Your action is now published! 🚀
See the versioning documentation
You can now consume the action by referencing the v1 branch
uses: actions/javascript-action@v1
with:
milliseconds: 1000
Add GitHub data to your README.md
, or any other file.
A GitHub action that provides template strings that are replaced with their respective values when the action runs.
By default, it takes TEMPLATE.md
and outputs README.md
.
name | required | type | default | description |
---|---|---|---|---|
token | yes | string | GitHub personal access token used to fetch data. Pass a secret by for instance using ${{ secrets.README_TEMPLATE_TOKEN }} . Go here to generate one with the read:user scope |
|
template | yes | string | "TEMPLATE.md" |
Template file path |
readme | yes | string | "README.md" |
Output file path |
Check out EXAMPLE_TEMPLATE.md
and EXAMPLE_OUTPUT.md
for more examples and their outputs.
Workflow:
name: Readme Template
on:
schedule:
- cron: '0 */2 * * *' # every 2 hours
push:
branches: [ master ]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Generate README.md
uses: probablykasper/readme-template-action@v1
with:
token: ${{ secrets.README_TEMPLATE_TOKEN }}
template: TEMPLATE.md
output: README.md
- name: Update README.md
run: |
if [[ "$(git status --porcelain)" != "" ]]; then
git config user.name "GitHub Action"
git config user.email "[email protected]"
git add .
git commit -m "Auto-update README.md"
git push
fi
See the actions tab for runs of this action! 🚀