Skip to content

Commit e9300b5

Browse files
authored
Merge pull request #2 from fabidick22/test-workflow2
test: add test file
2 parents 57e48c7 + 2923887 commit e9300b5

File tree

4 files changed

+65
-37
lines changed

4 files changed

+65
-37
lines changed

.github/workflows/build-app.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Build App
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'index.js'
9+
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- uses: tool3/ncc@v1
17+
with:
18+
github_token: ${{ github.token }}
19+
src: 'index.js'

.github/workflows/pr-metadata.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ jobs:
1010
runs-on: ubuntu-latest
1111
name: Annotates pull request with metadata
1212
steps:
13+
- uses: actions/checkout@v3
14+
1315
- name: Annotate PR
14-
uses: fabidick22/detect-changes-action@main
16+
uses: fabidick22/detect-changes-action@test-workflow2
1517
with:
1618
path: "dist/"
17-
token: "test"
19+
token: ${{ secrets.GITHUB_TOKEN }}

action.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ name: 'PR Metadata Action'
22
description: 'Adds pull request file changes as a comment to a newly opened PR'
33
inputs:
44
path:
5-
description: 'Paths list'
5+
description: 'Path'
66
required: false
7-
default: "."
7+
default: "./"
88
token:
99
description: 'The token to use to access the GitHub API'
10-
required: true
10+
required: false
11+
default: ${{ github.token }}
1112
runs:
1213
using: 'node16'
1314
main: 'dist/index.js'

index.js

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,47 @@
11
const core = require('@actions/core');
22
const github = require('@actions/github');
33

4-
const main = async () => {
5-
try {
6-
const path = core.getInput('path', { required: true });
7-
const token = core.getInput('token', { required: true });
8-
const regExp = RegExp(path)
9-
const octokit = new github.getOctokit(token);
10-
11-
const response = await octokit.rest.repos.compareCommits({
12-
owner: github.context.repo.owner,
13-
repo: github.context.repo.repo,
14-
base: "HEAD^",
15-
head: "HEAD"
16-
})
17-
18-
const filteredFiles = (response.data.files || []).filter(file => {
19-
let isMatch = regExp.test(file.filename)
20-
console.log(`[${isMatch && '[** match **]'} ${file.filename}`)
21-
console.log(`##Path: ${file.filename} matches`)
22-
return isMatch
4+
async function setOutputs(files) {
5+
const pathsChanged = []
6+
const filesChanged = []
7+
files.forEach(file => {
8+
pathsChanged.push(file.filename.split("/").slice(0, -1).join("/"))
9+
filesChanged.push(file.filename)
2310
})
11+
core.setOutput("paths_changed", JSON.stringify(pathsChanged))
12+
core.setOutput("file_changed", JSON.stringify(filesChanged))
13+
}
2414

25-
if(filteredFiles.length === 0){
26-
console.log("No matchs found.")
27-
console.log(`Raw input: ${directory}`)
28-
console.log(`Regex: ${regExp.toString()}`)
29-
core.setOutput("hasChanges", false)
15+
const main = async () => {
16+
try {
17+
const path = core.getInput('path', {required: false}) || "./"
18+
const token = core.getInput('token', {required: true})
19+
const pr = github.context.payload.pull_request
20+
const regExp = RegExp(path)
21+
const octokit = new github.getOctokit(token);
22+
23+
const response = await octokit.rest.pulls.listFiles({
24+
owner: github.context.repo.owner,
25+
repo: github.context.repo.repo,
26+
pull_number: pr.number
27+
})
28+
29+
const filteredFiles = (response.data || []).filter(file => {
30+
let isMatch = regExp.test(file.filename)
31+
console.log(`- ${isMatch} [** match **] ${file.filename}`)
32+
return isMatch
33+
})
34+
35+
if (filteredFiles.length === 0) {
36+
console.log("No matchs found.")
37+
console.log(`Raw input: ${directory}`)
38+
console.log(`Regex: ${regExp.toString()}`)
39+
}
40+
await setOutputs(filteredFiles);
41+
42+
} catch (error) {
43+
core.setFailed(error.message);
3044
}
31-
32-
console.log(`Found a total of ${filteredFiles.length} matches`)
33-
34-
core.setOutput("hasChanges", true)
35-
36-
} catch (error) {
37-
core.setFailed(error.message);
38-
}
3945
}
4046

4147
main();

0 commit comments

Comments
 (0)