-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
## path-watcher-action | ||
|
||
Given a comma-separated list of globs, returns whether the head commit that triggered the action involves a change in any of the input paths. | ||
|
||
Usage: | ||
|
||
``` | ||
on: [push] | ||
jobs: | ||
job: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- id: modified | ||
uses: pheel/path-watcher-action@v1 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} # no need to set this secret, it is always available! | ||
paths: 'dir1/**/*,dir2/**/*' | ||
- if: steps.modified.outputs.modified | ||
run: echo "Hey some change happened in one of your watched paths!" | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: 'path-watcher-action' | ||
description: 'check whether the head commit involved a change in one of the input paths' | ||
inputs: | ||
github_token: | ||
description: 'github token' | ||
paths: | ||
description: 'comma separated list of paths' | ||
required: true | ||
outputs: | ||
modified: | ||
description: 'whether the commit involves a change in any of the input paths' | ||
branding: | ||
icon: 'zoom-in' | ||
color: 'purple' | ||
runs: | ||
using: 'node12' | ||
main: 'index.js' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const core = require('@actions/core'); | ||
const github = require('@actions/github'); | ||
const Octokit = require("@octokit/rest"); | ||
const minimatch = require('minimatch'); | ||
|
||
try { | ||
const ghToken = core.getInput('github_token'); | ||
const octokit = new Octokit(ghToken ? { auth: ghToken } : {}); | ||
const paths = core.getInput('paths').split(','); | ||
const commit_sha = github.context.payload.head_commit.id; | ||
const [owner, repo] = github.context.payload.repository.full_name.split('/'); | ||
octokit.git.getCommit({ owner, repo, commit_sha }) | ||
.then(({ data: { files } }, err) => { | ||
if (err) throw new Error(err); | ||
if (Array.isArray(files)) { | ||
const modifiedPaths = files.map(f => f.filename); | ||
const modified = paths.some(p => minimatch.match(modifiedPaths, p).length); | ||
core.setOutput('modified', modified); | ||
} else { | ||
core.setOutput('modified', false); | ||
} | ||
}); | ||
} catch (error) { | ||
core.setFailed(error.message); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.