Skip to content

Commit df70b4b

Browse files
authored
Replace template data with the real action (#1)
* Replace template data with the real action * npm run all * npm install --save-dev eslint-config-standard eslint-plugin-promise eslint-plugin-import eslint-plugin-node * Return the whole stringified error * Compiled * console.log the error * log github and core keys * Add cache to the test action * Add core debug messages * Stringified debug variables * Fix PR base * Fix octokit.repos.compareCommits result structure * Fix no patch * Single quote outputs * Fix getLineNumbers * Exec git fetch * Don't use the cheout action * Test with branch realAction instead of local action * Re use the local action * Separate ref parsing into a new function: getRefs * git fetch from context repo * git fetch from origin * Use git diff, use include and ignore RegExps * core.error execAsync's errors * Don't fail git fetch on errors * Fix args * Fix for ambiguous argument 'main...ef6ee51': unknown revision or path not in the working tree. in getPaths * Add -- to git diff in getPaths * Change base ref to the sha
1 parent c2f4319 commit df70b4b

File tree

16 files changed

+11231
-8431
lines changed

16 files changed

+11231
-8431
lines changed

.eslintrc.json

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
{
2-
"env": {
3-
"commonjs": true,
4-
"es6": true,
5-
"jest": true,
6-
"node": true
7-
},
8-
"extends": "eslint:recommended",
9-
"globals": {
10-
"Atomics": "readonly",
11-
"SharedArrayBuffer": "readonly"
12-
},
13-
"parserOptions": {
14-
"ecmaVersion": 2018
15-
},
16-
"rules": {
17-
}
2+
"env": {
3+
"commonjs": true,
4+
"es6": true,
5+
"jest": true,
6+
"node": true
7+
},
8+
"extends": ["standard", "plugin:prettier/recommended"],
9+
"parserOptions": {
10+
"ecmaVersion": 2018
11+
}
1812
}

.github/workflows/test.yml

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: "units-test"
1+
name: "Test this action on this action"
22
on:
33
pull_request:
44
push:
@@ -7,19 +7,39 @@ on:
77
- 'releases/*'
88

99
jobs:
10-
# unit tests
11-
units:
10+
# ESLint
11+
lint:
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v2
15-
- run: npm ci
16-
- run: npm test
14+
- uses: actions/checkout@v2
1715

18-
# test action works running from the graph
19-
test:
16+
- name: Cache node modules
17+
uses: actions/cache@v2
18+
env:
19+
cache-name: cache-node-modules
20+
with:
21+
# npm cache files are stored in `~/.npm` on Linux/macOS
22+
path: ~/.npm
23+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
24+
restore-keys: |
25+
${{ runner.os }}-build-${{ env.cache-name }}-
26+
${{ runner.os }}-build-
27+
${{ runner.os }}-
28+
29+
- run: npm ci
30+
31+
- run: npm run lint
32+
33+
# test action
34+
testAction:
2035
runs-on: ubuntu-latest
2136
steps:
22-
- uses: actions/checkout@v2
23-
- uses: ./
24-
with:
25-
milliseconds: 1000
37+
- uses: actions/checkout@v2
38+
39+
- uses: ./
40+
id: diff
41+
with:
42+
include: '["\\.js$", "\\.jsx$"]'
43+
ignore: '["^dist/", "^bin/", "^www/"]'
44+
- name: Print line numbers of changed lines
45+
run: echo Line numbers = ${{ toJSON(steps.diff.outputs.lineNumbers) }}

.prettierrc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"singleQuote": true,
3+
"semi": false,
4+
"jsxSingleQuote": true,
5+
"trailingComma": "none",
6+
"arrowParens": "avoid",
7+
"endOfLine": "lf"
8+
}

CODEOWNERS

Lines changed: 0 additions & 1 deletion
This file was deleted.

LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

README.md

Lines changed: 42 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,55 @@
1-
# Create a JavaScript Action
1+
# Diff line numbers javascript action
22

3-
<p align="center">
4-
<a href="https://github.com/actions/javascript-action/actions"><img alt="javscript-action status" src="https://github.com/actions/javascript-action/workflows/units-test/badge.svg"></a>
5-
</p>
3+
This action outputs the line number of the deleted/added lines of modified or added files.
64

7-
Use this template to bootstrap the creation of a JavaScript action.:rocket:
5+
The line numbers are obtained by parsing the patch chunks of each file given by `git diff`
86

9-
This template includes tests, linting, a validation workflow, publishing, and versioning guidance.
7+
NOTE: Requires having used `actions/checkout@v2` in a previous step.
108

11-
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+
## Inputs
1210

13-
## Create an action from this template
11+
### `include`
1412

15-
Click the `Use this Template` and provide the new repo details for your action
13+
**Optional** JSON array. Only process paths that match a regular expression in `include`. By default includes all.
1614

17-
## Code in Main
15+
### `ignore`
1816

19-
Install the dependencies
17+
**Optional** JSON array. Do not process paths that match a regular expression in `ignore`. By default ignores none.
2018

21-
```bash
22-
npm install
23-
```
24-
25-
Run the tests :heavy_check_mark:
26-
27-
```bash
28-
$ npm test
29-
30-
PASS ./index.test.js
31-
✓ throws invalid number (3ms)
32-
wait 500 ms (504ms)
33-
test runs (95ms)
34-
...
35-
```
36-
37-
## Change action.yml
38-
39-
The action.yml 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
19+
## Outputs
4620

47-
Most toolkit and CI/CD operations involve async operations so the action is run in an async function.
21+
### `lineNumbers`
4822

23+
An array with the files' path, added lines and removed lines. It looks like:
4924
```javascript
50-
const core = require('@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()
63-
```
64-
65-
See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages.
66-
67-
## Package for distribution
68-
69-
GitHub Actions will run the entry point from the action.yml. Packaging assembles the code into one file that can be checked in to Git, enabling fast and reliable execution and preventing the need to check in node_modules.
70-
71-
Actions are run from GitHub repos. Packaging the action will create a packaged action in the dist folder.
72-
73-
Run prepare
74-
75-
```bash
76-
npm run prepare
25+
[
26+
{
27+
path: string,
28+
added: number[],
29+
removed: number[]
30+
},
31+
...
32+
]
33+
```
34+
- `path` is the file's path, e.g. `package.json` and `src/index.js`.
35+
- `added` is an array of numbers. Each number is the line number of an added line.
36+
- `removed` is an array of numbers. Each number is the line number of a removed line.
37+
38+
## Example usage
39+
40+
```yml
41+
name: example
42+
on: [pull_request]
43+
jobs:
44+
example:
45+
runs-on: ubuntu-latest
46+
steps:
47+
- name: Get diff lines
48+
id: diff
49+
uses: Equip-Collaboration/diff-line-numbers@v1
50+
with:
51+
include: '["\\.js$", "\\.jsx$"]'
52+
ignore: '["^dist/", "^bin/", "^www/"]'
53+
- name: Print line numbers of changed lines
54+
run: echo Line numbers = ${{ toJSON(steps.diff.outputs.lineNumbers) }}
7755
```
78-
79-
Since the packaged index.js is run from the dist folder.
80-
81-
```bash
82-
git add dist
83-
```
84-
85-
## Create a release branch
86-
87-
Users shouldn't consume the action from master since that would be latest code and actions can break compatibility between major versions.
88-
89-
Checkin to the v1 release branch
90-
91-
```bash
92-
git checkout -b v1
93-
git commit -a -m "v1 release"
94-
```
95-
96-
```bash
97-
git push origin v1
98-
```
99-
100-
Note: We recommend using the `--license` option for ncc, which will create a license file for all of the production node modules used in your project.
101-
102-
Your action is now published! :rocket:
103-
104-
See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)
105-
106-
## Usage
107-
108-
You can now consume the action by referencing the v1 branch
109-
110-
```yaml
111-
uses: actions/javascript-action@v1
112-
with:
113-
milliseconds: 1000
114-
```
115-
116-
See the [actions tab](https://github.com/actions/javascript-action/actions) for runs of this action! :rocket:

action.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
name: 'Wait'
2-
description: 'Wait a designated number of milliseconds'
1+
name: 'Diff line numbers'
2+
description: 'Outputs the line number of the deleted/added lines of modified or added files.'
33
inputs:
4-
milliseconds: # id of input
5-
description: 'number of milliseconds to wait'
6-
required: true
7-
default: '1000'
4+
include:
5+
description: 'JSON array. Only process paths that match a regular expression in `include`. By default includes all.'
6+
required: false
7+
default: '[""]'
8+
ignore:
9+
description: 'JSON array. Do not process paths that match a regular expression in `ignore`. By default ignores none.'
10+
required: false
11+
default: '[]'
812
outputs:
9-
time: # output will be available to future steps
10-
description: 'The message to output'
13+
lineNumbers:
14+
description: "{ path: string, added: number[], removed: number[] }[]"
1115
runs:
1216
using: 'node12'
1317
main: 'dist/index.js'

0 commit comments

Comments
 (0)