-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
name: "build-test" | ||
on: # rebuild any PRs and main branch changes | ||
name: ci | ||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- master | ||
- 'releases/*' | ||
|
||
jobs: | ||
build: # make sure build/ci work properly | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- uses: actions/checkout@v2 | ||
- run: | | ||
npm install | ||
npm run all | ||
test: # make sure the action works on a clean machine without building | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- uses: actions/checkout@v2 | ||
- uses: ./ | ||
with: | ||
milliseconds: 1000 | ||
with: | ||
api_key: abc123 | ||
github_token: ${{ secrets.GITHUB_TOKEN }} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
12.17.0 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
FROM node:lts AS builder | ||
WORKDIR /usr/app | ||
COPY package*.json ./ | ||
RUN npm ci | ||
COPY tsconfig.json . | ||
COPY src ./src | ||
RUN npm run build | ||
|
||
FROM node:lts | ||
WORKDIR /usr/app | ||
COPY package*.json ./ | ||
RUN npm ci --only=production | ||
COPY --from=builder /usr/app/lib ./lib | ||
CMD ["node", "/usr/app/lib/main.js"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,25 @@ | ||
<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> | ||
# Tinify Action | ||
|
||
# Create a JavaScript Action using TypeScript | ||
[GitHub Action](https://github.com/features/actions) to compress images with the [Tinify API](https://tinypng.com/developers). | ||
|
||
Use this template to bootstrap the creation of a JavaScript action.:rocket: | ||
![Example commit](https://i.imgur.com/FWOosON.png) | ||
|
||
This template includes compilication 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 Master | ||
|
||
Install the dependencies | ||
```bash | ||
$ npm install | ||
``` | ||
|
||
Build the typescript and package it for distribution | ||
```bash | ||
$ npm run build && npm run pack | ||
``` | ||
|
||
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() | ||
``` | ||
|
||
See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages. | ||
|
||
## Publish to a distribution branch | ||
|
||
Actions are run from GitHub repos so we will checkin the packed dist folder. | ||
|
||
Then run [ncc](https://github.com/zeit/ncc) and push the results: | ||
```bash | ||
$ npm run pack | ||
$ git add dist | ||
$ git commit -a -m "prod dependencies" | ||
$ git push origin releases/v1 | ||
``` | ||
|
||
Your action is now published! :rocket: | ||
|
||
See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) | ||
|
||
## Validate | ||
|
||
You can now validate the action by referencing `./` in a workflow in your repo (see [test.yml](.github/workflows/test.yml)]) | ||
## Usage | ||
|
||
```yaml | ||
uses: ./ | ||
with: | ||
milliseconds: 1000 | ||
name: image | ||
on: | ||
pull_request: | ||
types: [opened] | ||
jobs: | ||
compress: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
ref: ${{ github.head_ref }} | ||
- uses: namoscato/action-tinify@v1 | ||
with: | ||
api_key: ${{ secrets.TINIFY_API_KEY }} | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
``` | ||
See the [actions tab](https://github.com/actions/javascript-action/actions) for runs of this action! :rocket: | ||
## Usage: | ||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {getCommitMessage} from '../src/git-utils' | ||
import {Commit} from '../src/git' | ||
|
||
describe('getCommitMessage', () => { | ||
test('defined message', () => { | ||
const message = getCommitMessage({message: 'MESSAGE'} as Commit) | ||
expect(message).toEqual('MESSAGE') | ||
}) | ||
|
||
test('one file', () => { | ||
const message = getCommitMessage({ | ||
files: ['FILE'] | ||
} as any) | ||
expect(message).toEqual('Compress image') | ||
}) | ||
|
||
test('multiple files', () => { | ||
const message = getCommitMessage({ | ||
files: ['FILE1', 'FILE2'] | ||
} as any) | ||
expect(message).toEqual('Compress images') | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Image from '../src/image' | ||
|
||
let image: Image | ||
|
||
beforeEach(() => { | ||
image = new Image('FILE', [20000, 9876]) | ||
}) | ||
|
||
test('getFilename', () => { | ||
expect(image.getFilename()).toEqual('FILE') | ||
}) | ||
|
||
test('getCompressionSummary', () => { | ||
expect(image.getCompressionSummary()).toEqual('-9.89KB (-50%)') | ||
}) |