Skip to content

Commit

Permalink
Merge pull request #4 from gacts/add-error-handling
Browse files Browse the repository at this point in the history
v1.2.0
  • Loading branch information
jetexe committed Mar 24, 2023
2 parents df62547 + e7cef75 commit 2326bf0
Show file tree
Hide file tree
Showing 13 changed files with 779 additions and 54 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ jobs:
update-git-tag: # Reason: <https://github.com/actions/toolkit/blob/main/docs/action-versioning.md#recommendations>
name: Update latest major git tag
runs-on: ubuntu-20.04
permissions: write-all
steps:
- uses: actions/checkout@v3

Expand Down
31 changes: 17 additions & 14 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@ name: tests

on:
push:
branches: [master, main]
tags-ignore: ['**']
paths-ignore: ['**.md']
branches: [ master, main ]
tags-ignore: [ '**' ]
paths-ignore: [ '**.md' ]
pull_request:
paths-ignore: ['**.md']
paths-ignore: [ '**.md' ]

jobs:
gitleaks:
name: Gitleaks
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
with: {fetch-depth: 0}
with: { fetch-depth: 0 }

- name: Check for GitLeaks
uses: gacts/gitleaks@v1 # Action page: <https://github.com/gacts/gitleaks>

eslint:
name: Run eslint
runs-on: ubuntu-20.04
env: {FORCE_COLOR: 'true'}
env: { FORCE_COLOR: 'true' }
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with: {node-version: '16'}
with: { node-version: '16' }

- uses: actions/cache@v3
id: yarn-cache
Expand All @@ -46,12 +46,12 @@ jobs:
runs-on: ubuntu-20.04
outputs:
dist-changed: ${{ steps.state.outputs.changed }}
env: {FORCE_COLOR: 'true'}
env: { FORCE_COLOR: 'true' }
steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with: {node-version: '16'}
with: { node-version: '16' }

- uses: actions/cache@v3
id: yarn-cache
Expand All @@ -66,14 +66,14 @@ jobs:
- run: yarn build

- uses: actions/upload-artifact@v3
with: {name: dist, path: ./dist/, retention-days: 1}
with: { name: dist, path: ./dist/, retention-days: 1 }

- id: state
run: echo "changed=`git diff --diff-filter=ACMUXTR --name-only | grep dist/ > /dev/null && echo 'true' || echo 'false'`" >> $GITHUB_OUTPUT

commit-and-push-fresh-dist:
name: Commit and push fresh distributive
needs: [dist-built]
needs: [ dist-built ]
if: ${{ needs.dist-built.outputs.dist-changed == 'true' }}
runs-on: ubuntu-20.04
permissions:
Expand All @@ -83,7 +83,7 @@ jobs:
- uses: actions/checkout@v3

- uses: actions/download-artifact@v3
with: {name: dist, path: ./dist/}
with: { name: dist, path: ./dist/ }

- uses: stefanzweifel/git-auto-commit-action@v4
with:
Expand All @@ -98,8 +98,11 @@ jobs:
- name: Run this action
uses: ./
with:
run: echo "First run"
post: echo "First post"
run: echo "First"
"(can be multiline)"
post: |
echo "First post"
echo "(can run multiply commands)"
- name: Run this action with only post
uses: ./
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ All notable changes to this package will be documented in this file.

The format is based on [Keep a Changelog][keepachangelog] and this project adheres to [Semantic Versioning][semver].

## v1.1.0

### Added

- `run` and `post` parameters now can be a list of commands

### Changed

- `post` parameter is required now
- `post` command will run even if workflow has errors

### Fixed

- Removed stacktrace from error

## v1.0.0

### Added
Expand Down
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ jobs:
- name: Run this action
uses: gacts/run-and-post-run@v1
with:
run: echo "First run"
post: echo "First post"
run: echo "First"
"(can be multiline)"
post: |
echo "First post"
echo "(can run multiply commands)"
- name: Run this action with only post
uses: gacts/run-and-post-run@v1
with:
post: echo "Second post"

```

This above configuration will produce the following:
Expand All @@ -40,11 +44,11 @@ This above configuration will produce the following:

Following inputs can be used as `step.with` keys:

| Name | Type | Default | Required | Description |
|---------------------|:--------:|:-------:|:--------:|---------------------------------------------------------------|
| `run` | `string` | | no | A command that needs to be run in place. |
| `post` | `string` | | no | A command that needs to be run once a workflow job has ended. |
| `working-directory` | `string` | | no | A working directory from which the command needs to be run. |
| Name | Type | Default | Required | Description |
|---------------------|:------------------:|:-------:|:--------:|----------------------------------------------------------------|
| `run` | `string` or `list` | | no | A commands that needs to be run in place. |
| `post` | `string` or `list` | | yes | A commands that needs to be run once a workflow job has ended. |
| `working-directory` | `string` | | no | A working directory from which the command needs to be run. |

## Releasing

Expand Down
7 changes: 3 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@ description: A simple GitHub action that allows you to execute commands on place

inputs:
run:
description: A command that needs to be run in place.
description: A command or list of commands that needs to be run in place.
required: false
post:
description: A command that needs to be run once a workflow job has ended.
description: A command or list of commands that needs to be run once a workflow job has ended.
required: true
working-directory:
description: "A working directory from which the command needs to be run."
description: A working directory from which the command needs to be run.
required: false

runs:
using: 'node16'
main: 'dist/main/index.js'
post: 'dist/post/index.js'
post-if: success()

branding:
icon: cloud-lightning
Expand Down
2 changes: 1 addition & 1 deletion dist/main/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/post/index.js

Large diffs are not rendered by default.

Binary file modified docs/ci-example.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions src/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const core = require("@actions/core"); // https://github.com/actions/toolkit/tree/main/packages/core
const exec = require("@actions/exec"); // https://github.com/actions/toolkit/tree/main/packages/exec

// read action inputs
const input = {
run: core.getMultilineInput('run'),
post: core.getMultilineInput('post', {required: true}),
workingDirectory: core.getInput('working-directory'),
};

export async function run() {
return runCommands(input.run)
}

export async function post() {
return runCommands(input.post)
}

async function runCommands(commands) {
return (async () => {
for (const command of commands) {
if (command !== "") {
await exec.exec(command, [], {cwd: input.workingDirectory});
}
}
})().catch(error => core.error(error.message))
}

15 changes: 2 additions & 13 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
const core = require("@actions/core"); // https://github.com/actions/toolkit/tree/main/packages/core
const exec = require("@actions/exec"); // https://github.com/actions/toolkit/tree/main/packages/exec

// read action inputs
const input = {
run: core.getInput('run'),
workingDirectory: core.getInput('working-directory'),
};
const {run} = require("./common");

(async () => {
const command = input.run

if (command !== "") {
await exec.exec(command, [], {cwd: input.workingDirectory});
}
await run()
})();
15 changes: 2 additions & 13 deletions src/post.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
const core = require("@actions/core"); // https://github.com/actions/toolkit/tree/main/packages/core
const exec = require("@actions/exec"); // https://github.com/actions/toolkit/tree/main/packages/exec

// read action inputs
const input = {
post: core.getInput('post', {required: true}),
workingDirectory: core.getInput('working-directory'),
};
const {post} = require("./common");

(async () => {
const command = input.post

if (command !== "") {
await exec.exec(command, [], {cwd: input.workingDirectory});
}
await post()
})();

0 comments on commit 2326bf0

Please sign in to comment.