8000 feat(*): next try · shiftcode/github-action-skip@d368410 · GitHub
[go: up one dir, main page]

Skip to content

Commit d368410

Browse files
feat(*): next try
1 parent b63de80 commit d368410

File tree

6 files changed

+80
-106
lines changed

6 files changed

+80
-106
lines changed

.github/workflows/test.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ jobs:
99
test:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v1
13-
- run: npm ci
14-
- run: npm run build
15-
- uses: ./
12+
- uses: actions/checkout@v2
13+
- name: Install dependencies
14+
run: npm ci
15+
- name: Build
16+
run: npm run build
17+
- name: Check for Execution
18+
uses: ./
1619
with:
1720
skipOnCommitMsg: "sample"
21+
ghToken: ${{secrects.GH_TOKEN_3}}
1822
- name: Some Job
1923
run: echo "sample"

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
__tests__/runner/*
22

33
# comment out in distribution branches
4-
#node_modules/
4+
# node_modules/
55

66
# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore
77
# Logs

README.md

Lines changed: 32 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,47 @@
1-
# Create a JavaScript Action using TypeScript
1+
# shiftcode/github-action-skip
22

3-
Use this template to bootstrap the creation of a JavaScript action.:rocket:
3+
Github Actions have [native support](https://github.blog/changelog/2021-02-08-github-actions-skip-pull-request-and-push-workflows-with-skip-ci/) to skip an entire workflow depending on commit message. But since we rely on status checks
4+
for our Pull Requests to be green, we need another option.
45

5-
This template includes compilication support, tests, a validation workflow, publishing, and versioning guidance.
6+
This action accepts an input string `skipOnCommitMsg` which will be used to check if the commit message contains the given string.
7+
If yes the output `shouldExecute` will be set to `false`. `true` otherwise. For full input / output list and other configurations check [`action.yml`](./action.yml).
68

7-
If you are new, there's also a simpler introduction. See the [Hello World JavaScript Action](https://github.com/actions/hello-world-javascript-action)
9+
## Example GitHub Workflow definition
10+
This example shows how to setup two dependant jobs, the second will only be executed if the output from `checkExecution` job is `false`.
811

9-
## Create an action from this template
10-
11-
Click the `Use this Template` and provide the new repo details for your action
12-
13-
## Code in Master
14-
15-
Install the dependencies
16-
```bash
17-
$ npm install
18-
```
19-
20-
Build the typescript
21-
```bash
22-
$ npm run build
23-
```
24-
25-
Run the tests :heavy_check_mark:
26-
```bash
27-
$ npm test
28-
29-
PASS ./index.test.js
30-
✓ throws invalid number (3ms)
31-
wait 500 ms (504ms)
32-
test runs (95ms)
33-
34-
...
35-
```
36-
37-
## Change action.yml
38-
39-
The action.yml contains defines the inputs and output for your action.
40-
41-
Update the action.yml with your name, description, inputs and outputs for your action.
42-
43-
See the [documentation](https://help.github.com/en/articles/metadata-syntax-for-github-actions)
44-
45-
## Change the Code
46-
47-
Most toolkit and CI/CD operations involve async operations so the action is run in an async function.
48-
49-
```javascript
50-
import * as core from '@actions/core';
51-
...
52-
53-
async function run() {
54-
try {
55-
...
56-
}
57-
catch (error) {
58-
core.setFailed(error.message);
59-
}
60-
}
61-
62-
run()
12+
```yaml
13+
# jobs
14+
checkExecution:
15+
runs-on: ubuntu-latest
16+
outputs:
17+
shouldExecute: ${{steps.step1.outputs.shouldExecute}}
18+
steps:
19+
- name: Check for execution
20+
uses: shiftcode/github-action-skip@releases/v2-alpha.0
21+
with:
22+
skipOnCommitMsg: "[skip_workflow]"
23+
build:
24+
runs-on: ubuntu-latest
25+
needs: checkExecution
26+
if: needs.checkExecution.outputs.shouldExecute
27+
steps:
6328
```
6429
65-
See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages.
66-
6730
## Publish to a distribution branch
6831
69-
Actions are run from GitHub repos. We will create a releases branch and only checkin production modules (core in this case).
32+
Actions will be consumed from GitHub repos. All the dependencies must be pushed there. This means for JS also
33+
`node_module` must be published.
7034

71-
Comment out node_modules in .gitignore and create a releases/v1 branch
35+
Comment out `node_modules` in [.gitignore](./.gitignore) and create a `releases/**` branch
7236
```bash
7337
# comment out in distribution branches
7438
# node_modules/
7539
```
7640

77-
```bash
78-
$ git checkout -b releases/v1
79-
$ git commit -a -m "prod dependencies"
80-
```
41+
Then run the following commands:
8142

8243
```bash
44+
$ git checkout -b releases/v1
8345
$ npm prune --production
8446
$ git add node_modules
8547
$ git commit -a -m "prod dependencies"
@@ -90,24 +52,13 @@ Your action is now published! :rocket:
9052

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

93-
## Validate
94-
95-
You can now validate the action by referencing the releases/v1 branch
96-
97-
```yaml
98-
uses: actions/typescript-action@releases/v1
99-
with:
100-
milliseconds: 1000
101-
```
102-
103-
See the [actions tab](https://github.com/actions/javascript-action/actions) for runs of this action! :rocket:
104-
10555
## Usage:
10656

10757
After testing you can [create a v1 tag](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md) to reference the stable and tested action
10858

10959
```yaml
110-
uses: actions/typescript-action@v1
60+
uses: shiftcode/github-action-skip@v1
11161
with:
112-
milliseconds: 1000
113-
```
62+
skipOnCommitMsg: "[skip build]"
63+
githubtoken: ${{secrets.GH_TOKEN}}
64+
```

action.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
# check doc on https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs
12
name: 'Skip CI'
2-
description: 'Skip ci based on some input parameter'
3+
description: 'Sets output param depending on commit message'
34
author: 'Michael Wittwer <michael.wittwer@shiftcode.ch>'
45
inputs:
5-
skipOnCommitMsg: # change this
6-
description: 'will cancel the current action if the commit message contains tiven value'
6+
skipOnCommitMsg:
7+
description: 'defines an output variable depending if the commit message contains the skipOnCommitMsg string (output: true) or not (false).'
78
default: ''
89
required: true
10+
outputs:
11+
shouldExecute:
12+
description: 'boolean value. True if the commit message contains the string provided in skipOnCommitMsg input param, false otherwise.'
913
runs:
10-
using: 'node12'
14+
using: 'node16'
1115
main: 'lib/main.js'

publish.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
branchName="releases/v2-alpha.1"
2+
echo branch name $branchName
3+
4+
# prior to execute this command make sure to comment the line#4 where node_modules are ignored in .gitignore file
5+
git checkout -b $branchName
6+
# only install dependencies required during executino (no devDeps)
7+
npm prune --production
8+
git add node_modules
9+
git commit -a -m "add runtime (prod) dependencies"
10+
#git push origin $branchName

src/main.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
import * as core from '@actions/core'
2-
// import * as git from '@actions/github'
3-
4-
const INPUT = 'skipOnCommitMsg'
2+
import * as github from '@actions/github'
53

4+
enum INPUT_PARAMS{
5+
SKIP_ON_COMMIT_MSG = 'skipOnCommitMsg',
6+
GH_TOKEN = 'githubToken'
7+
}
68
async function run() {
79
try {
8-
core.debug('start working')
9-
const skipOnCommitMsg = core.getInput(INPUT)
10-
console.log(`skip CI on commit message ${skipOnCommitMsg}`)
11-
core.setOutput('shouldExecute', false)
12-
// `<!--stopping here, because the commit message contains the provided input <${skipOnCommitMsg}>-->`)
13-
// const ghToken = core.getInput()
14-
// git.getOctokit()
15-
// console.log(git.context.payload)
16-
// const commitMessage = git.context.payload.comment
17-
// console.log('commit message', commitMessage)
18-
// if (commitMessage.includes(skipOnCommitMsg)) {
19-
// core.setFailed(`stopping here, because the commit message contains the provided input <${skipOnCommitMsg}>`)
20-
// }
10+
const skipOnCommitMsg = core.getInput(INPUT_PARAMS.SKIP_ON_COMMIT_MSG)
11+
const ghToken = core.getInput(INPUT_PARAMS.GH_TOKEN)
12+
13+
core.debug(`reading git commit message to resolve the output variable, output variable will be true if commit message contains message "${skipOnCommitMsg}"`)
14+
15+
const octokit = github.getOctokit(ghToken)
16+
octokit.rest
17+
18+
if(true){
19+
core.setOutput('shouldExecute', false)
20+
} else {
21+
core.setOutput('shouldExecute', true)
22+
}
2123
} catch (error) {
24+
core.error('there was an error')
2225
if(error instanceof Error){
2326
core.setFailed(error.message)
2427
}
28+
29+
core.setFailed(error)
2530
}
2631
}
2732

0 commit comments

Comments
 (0)
0