Skip to content

Commit

Permalink
major: initial implementation of retry step
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Fields committed Feb 13, 2020
1 parent a6a097a commit d4e983a
Show file tree
Hide file tree
Showing 14 changed files with 8,341 additions and 3 deletions.
10 changes: 10 additions & 0 deletions .commitlintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'type-enum': [
2,
'always',
['feat', 'fix', 'docs', 'style', 'refactor', 'test', 'revert', 'patch', 'minor', 'major'],
],
},
};
72 changes: 72 additions & 0 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: CI/CD
on:
push:
branches:
- '**'
jobs:
# runs on branch pushes only
ci:
name: Run Tests
if: startsWith(github.ref, 'refs/heads')
runs-on: ubuntu-18.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 12
- name: Install dependencies
run: npm ci
- name: Test
uses: ./
continue-on-error: true
with:
timeout_minutes: 1
max_attempts: 3
command: npm install this-isnt-a-real-package-name-zzz
- name: happy-path
uses: ./
with:
timeout_minutes: 1
max_attempts: 2
command: npm -v
- name: sad-path (error)
uses: ./
continue-on-error: true
with:
timeout_minutes: 1
max_attempts: 2
command: node -e "process.exit(1)"
- name: sad-path (timeout)
uses: ./
continue-on-error: true
with:
timeout_minutes: 1
max_attempts: 2
command: node -e "(async()=>await new Promise(r => setTimeout(r, 120000)))()"

# runs on push to master only
cd:
name: Publish Action
needs: ci
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-18.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Node.js
uses: actions/setup-node@v1
with:
node-version: 12
- name: Install dependencies
run: npm ci
- name: Release
id: release
uses: cycjimmy/semantic-release-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Tag
run: git tag -f zzz && git push origin zzz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ typings/

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
Expand Down
7 changes: 7 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
tabWidth: 2,
printWidth: 100,
semi: true,
singleQuote: true,
trailingComma: 'es5',
};
22 changes: 22 additions & 0 deletions .releaserc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module.exports = {
plugins: [
[
'@semantic-release/commit-analyzer',
{
releaseRules: [
{ type: 'docs', scope: 'README', release: 'patch' },
{ type: 'minor', release: 'minor' },
{ type: 'major', release: 'major' },
{ type: 'patch', release: 'patch' },
{ scope: 'no-release', release: false },
],
},
],
'@semantic-release/release-notes-generator',
'@semantic-release/github',
],
branches: [
{ name: 'master' },
{ name: 'develop', channel: 'develop', prerelease: 'develop' }, // `prerelease` is set to `beta` as it is the value of `name`
],
};
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"editor.formatOnSave": true,
"prettier.requireConfig": true,
"typescript.tsdk": "node_modules/typescript/lib",
"editor.tabSize": 2
}
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,35 @@
# retry-step
Retries a GitHub Action step on failure or timeout
# retry

Retries an Action step on failure or timeout. This is currently intended to replace the `run` step for moody commands.

## Inputs

### `timeout_minutes`

**Required** Minutes to wait before attempt times out

### `max_attempts`

**Required** Number of attempts to make before failing the step

### `command`

**Required** The command to run

### `retry_wait_seconds`

**Optional** Number of seconds to wait before attempting the next retry. Defaults to `10`

### `polling_interval_seconds`

**Optional** Number of seconds to wait while polling for command result. Defaults to `1`

## Example usage

```yaml
uses: nick-invision/retry@v1
with:
timeout_minutes: 10
max_attempts: 3
command: npm install
```
24 changes: 24 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Retry Step
description: 'Retry a step on failure or timeout'
inputs:
timeout_minutes:
description: Minutes to wait before attempt times out
required: true
max_attempts:
description: Number of attempts to make before failing the step
required: true
default: 3
command:
description: The command to run
required: true
retry_wait_seconds:
description: Number of seconds to wait before attempting the next retry
required: false
default: 10
polling_interval_seconds:
description: Number of seconds to wait for each check that command has completed running
required: false
default: 1
runs:
using: 'node12'
main: 'dist/index.js'
8 changes: 8 additions & 0 deletions dist/exec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const { execSync } = require('child_process');
const COMMAND = process.argv.splice(2)[0];

function run() {
execSync(COMMAND, { stdio: 'inherit' });
}

run();
Loading

0 comments on commit d4e983a

Please sign in to comment.