4 KiB
Usage
Pre-requisites
Create a workflow .yml
file in your repositories .github/workflows
directory. An example workflow is available below. For more information, reference the GitHub Help Documentation for Creating a workflow file.
Inputs
path
- A list of files, directories, and wildcard patterns to cache and restore. See@actions/glob
for supported patterns.key
- An explicit key for restoring and saving the cacherestore-keys
- An ordered list of keys to use for restoring the cache if no cache hit occurred for keybucket
- aws s3 bucketaccess-key-id
- aws access key id OPTIONALsecret-access-key
- aws secret access key OPTIONAL
Outputs
cache-hit
- A boolean value to indicate an exact match was found for the key
See Skipping steps based on cache-hit for info on using this output
Cache scopes
The cache is scoped to the key and branch. The default branch cache is available to other branches.
See Matching a cache key for more info.
Example workflow
name: Caching Node Modules
on: push
jobs:
build-with-cache:
name: NPM Install with Cache
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v2
- uses: hipcamp/cache@v0.13.0
id: node-cache
with:
bucket: [your cache bucket]
path: node_modules
key: node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
node-
- run: npm install
Skipping steps based on cache-hit
Using the cache-hit
output, subsequent steps (such as install or build) can be skipped when a cache hit occurs on the key.
Example:
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
id: cache
with:
path: path/to/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: /install.sh
Note: The
id
defined inactions/cache
must match theid
in theif
statement (i.e.steps.[ID].outputs.cache-hit
)
How to Contribute
First, you'll need to have a reasonably modern version of
node
handy. This won't work with versions older than 9, for instance.
Install the dependencies
$ npm install
Build the typescript and package it for distribution
$ npm run build && npm run package
Run the tests ✔️
$ npm test
PASS ./index.test.js
✓ throws invalid number (3ms)
✓ wait 500 ms (504ms)
✓ test runs (95ms)
...
Change action.yml
The action.yml contains 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
Change the Code
Most toolkit and CI/CD operations involve async operations so the action is run in an async function.
import * as core from '@actions/core';
...
async function run() {
try {
...
}
catch (error) {
core.setFailed(error.message);
}
}
run()
See the toolkit documentation for the various packages.
Publish to a Distribution Branch
Actions are run from GitHub repos so we will checkin the packed dist folder.
$ npm run all
$ git add -A
$ git commit -m "your commit message"
$ git tag v[version from package.json]
$ git push origin v[version from package.json]
Your action is now published! 🚀
See the versioning documentation