Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarchambault committed Aug 14, 2020
1 parent e5977b6 commit b898bd2
Show file tree
Hide file tree
Showing 24 changed files with 6,210 additions and 8,597 deletions.
11 changes: 5 additions & 6 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"plugins": ["jest", "@typescript-eslint"],
"plugins": ["@typescript-eslint"],
"extends": ["plugin:github/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
Expand All @@ -13,7 +13,7 @@
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
"@typescript-eslint/no-require-imports": "error",
"@typescript-eslint/no-require-imports": "warn",
"@typescript-eslint/array-type": "error",
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/ban-ts-comment": "error",
Expand All @@ -23,7 +23,7 @@
"@typescript-eslint/func-call-spacing": ["error", "never"],
"@typescript-eslint/no-array-constructor": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-explicit-any": "warn",
"@typescript-eslint/no-extraneous-class": "error",
"@typescript-eslint/no-for-in-array": "error",
"@typescript-eslint/no-inferrable-types": "error",
Expand All @@ -33,7 +33,7 @@
"@typescript-eslint/no-unnecessary-qualifier": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"@typescript-eslint/no-useless-constructor": "error",
"@typescript-eslint/no-var-requires": "error",
"@typescript-eslint/no-var-requires": "warn",
"@typescript-eslint/prefer-for-of": "warn",
"@typescript-eslint/prefer-function-type": "warn",
"@typescript-eslint/prefer-includes": "error",
Expand All @@ -48,7 +48,6 @@
},
"env": {
"node": true,
"es6": true,
"jest/globals": true
"es6": true
}
}
18 changes: 9 additions & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
name: 'build-test'
on: # rebuild any PRs and main branch changes
on:
pull_request:
push:
branches:
- main
- 'releases/*'

jobs:
build: # make sure build/ci work properly
runs-on: ubuntu-latest
test:
strategy:
matrix:
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v2
- run: |
npm install
- run: |
npm run all
test: # make sure the action works on a clean machine without building
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./
with:
milliseconds: 1000
root: test
- run: cd test && ./sbt compile
shell: bash
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ Thumbs.db

# Ignore built ts files
__tests__/runner/*
lib/**/*
lib/**/*
114 changes: 28 additions & 86 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,101 +1,43 @@
<p align="center">
<a href="https://github.com/actions/typescript-action/actions"><img alt="typescript-action status" src="https://github.com/actions/typescript-action/workflows/build-test/badge.svg"></a>
</p>
# coursier cache action

# Create a JavaScript Action using TypeScript
A GitHub action to save / restore the coursier cache of your build.

Use this template to bootstrap the creation of a TypeScript action.:rocket:
## Usage

This template includes compilation support, tests, a validation workflow, publishing, and versioning guidance.

If you are new, there's also a simpler introduction. See the [Hello World JavaScript Action](https://github.com/actions/hello-world-javascript-action)

## Create an action from this template

Click the `Use this Template` and provide the new repo details for your action

## Code in Main

Install the dependencies
```bash
$ npm install
```

Build the typescript and package it for distribution
```bash
$ npm run build && npm run package
```

Run the tests :heavy_check_mark:
```bash
$ 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](https://help.github.com/en/articles/metadata-syntax-for-github-actions)

## Change the Code

Most toolkit and CI/CD operations involve async operations so the action is run in an async function.

```javascript
import * as core from '@actions/core';
...

async function run() {
try {
...
}
catch (error) {
core.setFailed(error.message);
}
}

run()
Add a `coursier/cache-action@v1` step to your YAML workflow, like
```yaml
steps:
- uses: actions/checkout@v2
- uses: coursier/cache-action@v1
```
See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages.

## Publish to a distribution branch
## Parameters
Actions are run from GitHub repos so we will checkin the packed dist folder.
### `root`

Then run [ncc](https://github.com/zeit/ncc) and push the results:
```bash
$ npm run package
$ git add dist
$ git commit -a -m "prod dependencies"
$ git push origin releases/v1
```
*Optional* Root directory containing build definition sources (`build.sbt`, `build.sc`, etc.)

Your action is now published! :rocket:
If the sbt or mill build definition files are in a sub-directory, pass the path to this
sub-directory here.

See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)
### `path`

## Validate
*Optional* Override for the path of the coursier cache.

You can now validate the action by referencing `./` in a workflow in your repo (see [test.yml](.github/workflows/test.yml))
By default, the coursier cache is assumed to be in the [default OS-dependent location](https://get-coursier.io/docs/cache.html#default-location).
Set this input to override that. Note that this action will also set the `COURSIER_CACHE` environment variable
if an override is specified, so that you don't have to set it yourself.

```yaml
uses: ./
with:
milliseconds: 1000
```
### `extraFiles`

See the [actions tab](https://github.com/actions/javascript-action/actions) for runs of this action! :rocket:
*Optional* Extra files to take into account in the cache key.

## Usage:
By default, sbt build definition files (`*.sbt`, `project/**.{scala,sbt}`, `project/build.properties`) and
mill build definition files (`*.sc`, `./mill`) are hashed to uniquely identify the cached data. Upon
cache restoration, if an exact match is found, the cache is not saved again at the end of the job.
In case of no exact match, it is assumed new files may have been fetched; the previous cache for the
current OS, if any, is restored, but a new cache is persisted with a new key at the end of the job.

After testing you can [create a v1 tag](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) to reference the stable and latest V1 action
To take into account extra files in the cache key, pass via `extraFiles` either
- a single path as a string
- multiple paths in a JSON array, encoded in a string
27 changes: 0 additions & 27 deletions __tests__/main.test.ts

This file was deleted.

45 changes: 37 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
name: 'Your name here'
description: 'Provide a description here'
author: 'Your name or organization here'
name: 'coursier-cache-action'
description: 'Restores and saves the coursier cache'
author: 'Alexandre Archambault'
branding:
icon: 'arrow-down'
color: 'white'
inputs:
milliseconds: # change this
required: true
description: 'input description here'
default: 'default value if applicable'
root:
required: false
description: >
Root directory containing build definition sources (build.sbt, build.sc, etc.)
If the sbt or mill build definition files are in a sub-directory, pass the path to this
sub-directory here.
default: '.'
path:
required: false
description: >
Override for the path of the coursier cache.
By default, the coursier cache is assumed to be in the default OS-dependent location.
Set this input to override that. Note that this action will also set COURSIER_CACHE
if an override is specified, so that you don't have to set it yourself.
default: ''
extraFiles:
required: false
description: >
Extra files to take into account in the cache key.
By default, sbt build definition files (*.sbt, project/**.{scala,sbt}, project/build.properties) and
mill build definition files (*.sc, ./mill) are hashed to uniquely identify the cached data. Upon
cache restoration, if an exact match is found, the cache is not saved again at the end of the job.
In case of no exact match, it is assumed new files may have been fetched; the previous cache for the
current OS, if any, is restored, but a new cache is persisted with a new key at the end of the job.
To take into account extra files in the cache key, pass via extraFiles either
- a single path as a string
- multiple paths in a JSON array, encoded in a string
default: ''
runs:
using: 'node12'
main: 'dist/index.js'
main: 'dist/restore/index.js'
post: 'dist/save/index.js'
post-if: 'success()'
Loading

0 comments on commit b898bd2

Please sign in to comment.