If you are new, there's also a simpler introduction in the Hello world JavaScript action repository.
After testing, you can create version tag(s) that developers can use to reference different stable versions of your action. For more information, see Versioning in the GitHub Actions toolkit.
To include the action in a workflow in another repository, you can use the
uses
syntax with the @
symbol to reference a specific branch, tag, or commit
hash.
steps:
- name: Extract env from pr body
id: test-action
uses: 36node/action-pr-env@v1 # Commit with the `v1` tag
with:
text: '${{ github.event.pull_request.body }}'
- name: Print Output
id: output
run: echo "${{ steps.test-action.outputs.env }}"
After you've cloned the repository to your local machine or codespace, you'll need to perform some initial setup steps before you can develop your action.
Note
You'll need to have a reasonably modern version of
Node.js handy (20.x or later should work!). If you are
using a version manager like nodenv
or
nvm
, this template has a .node-version
file at the root of the repository that will be used to automatically switch
to the correct version when you cd
into the repository. Additionally, this
.node-version
file is used by GitHub Actions in any actions/setup-node
actions.
-
🛠️ Install the dependencies
npm install
-
🏗️ Package the TypeScript for distribution
npm run bundle
-
✅ Run the tests
$ npm test PASS ./index.test.js ✓ throws invalid number (3ms) ✓ wait 500 ms (504ms) ✓ test runs (95ms) ...
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4
- name: Test Local Action
id: test-action
uses: ./
with:
milliseconds: 1000
- name: Print Output
id: output
run: echo "${{ steps.test-action.outputs.time }}"
This project includes a helper script designed to streamline the process of tagging and pushing new releases for GitHub Actions.
GitHub Actions allows users to select a specific version of the action to use, based on release tags. Our script simplifies this process by performing the following steps:
- Retrieving the latest release tag: The script starts by fetching the most recent release tag by looking at the local data available in your repository.
- Prompting for a new release tag: The user is then prompted to enter a new release tag. To assist with this, the script displays the latest release tag and provides a regular expression to validate the format of the new tag.
- Tagging the new release: Once a valid new tag is entered, the script tags the new release.
- Pushing the new tag to the remote: Finally, the script pushes the new tag to the remote repository. From here, you will need to create a new release in GitHub and users can easily reference the new tag in their workflows.