mirror of
https://github.com/tj-actions/changed-files
synced 2024-12-17 03:47:20 +00:00
feat: add support for forcing the use of GitHub’s REST API (#1849)
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
parent
a57f4dcc81
commit
0ca1c07b47
7 changed files with 58 additions and 6 deletions
29
.github/workflows/multi-job-test.yml
vendored
29
.github/workflows/multi-job-test.yml
vendored
|
@ -36,3 +36,32 @@ jobs:
|
||||||
- name: List all changed files
|
- name: List all changed files
|
||||||
run: |
|
run: |
|
||||||
echo '${{ needs.changed-files.outputs.all_changed_files }}'
|
echo '${{ needs.changed-files.outputs.all_changed_files }}'
|
||||||
|
|
||||||
|
|
||||||
|
changed-files-rest-api:
|
||||||
|
name: Get changed files using REST API
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
all_changed_files: ${{ steps.changed-files.outputs.all_changed_files }}
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Get changed files
|
||||||
|
id: changed-files
|
||||||
|
continue-on-error: ${{ github.event_name == 'push' }}
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
use_rest_api: true
|
||||||
|
- name: List all changed files
|
||||||
|
run: echo '${{ steps.changed-files.outputs.all_changed_files }}'
|
||||||
|
|
||||||
|
view-changed-files-rest-api:
|
||||||
|
name: View all changed files using REST API
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: [changed-files-rest-api]
|
||||||
|
steps:
|
||||||
|
- name: List all changed files
|
||||||
|
run: |
|
||||||
|
echo '${{ needs.changed-files-rest-api.outputs.all_changed_files }}'
|
||||||
|
|
2
.github/workflows/workflow-run-test.yml
vendored
2
.github/workflows/workflow-run-test.yml
vendored
|
@ -1,4 +1,4 @@
|
||||||
name: Workflow Run Exmaple
|
name: Workflow Run Example
|
||||||
on:
|
on:
|
||||||
workflow_run:
|
workflow_run:
|
||||||
workflows: [Matrix Test]
|
workflows: [Matrix Test]
|
||||||
|
|
|
@ -203,6 +203,10 @@ inputs:
|
||||||
description: "Github API URL."
|
description: "Github API URL."
|
||||||
required: false
|
required: false
|
||||||
default: ${{ github.api_url }}
|
default: ${{ github.api_url }}
|
||||||
|
use_rest_api:
|
||||||
|
description: "Force the use of Github's REST API even when a local copy of the repository exists"
|
||||||
|
required: false
|
||||||
|
default: "false"
|
||||||
fail_on_initial_diff_error:
|
fail_on_initial_diff_error:
|
||||||
description: "Fail when the initial diff fails."
|
description: "Fail when the initial diff fails."
|
||||||
required: false
|
required: false
|
||||||
|
|
BIN
dist/index.js
generated
vendored
BIN
dist/index.js
generated
vendored
Binary file not shown.
BIN
dist/index.js.map
generated
vendored
BIN
dist/index.js.map
generated
vendored
Binary file not shown.
|
@ -53,6 +53,7 @@ export type Inputs = {
|
||||||
failOnInitialDiffError: boolean
|
failOnInitialDiffError: boolean
|
||||||
failOnSubmoduleDiffError: boolean
|
failOnSubmoduleDiffError: boolean
|
||||||
negationPatternsFirst: boolean
|
negationPatternsFirst: boolean
|
||||||
|
useRestApi: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getInputs = (): Inputs => {
|
export const getInputs = (): Inputs => {
|
||||||
|
@ -228,6 +229,10 @@ export const getInputs = (): Inputs => {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const useRestApi = core.getBooleanInput('use_rest_api', {
|
||||||
|
required: false
|
||||||
|
})
|
||||||
|
|
||||||
const inputs: Inputs = {
|
const inputs: Inputs = {
|
||||||
files,
|
files,
|
||||||
filesSeparator,
|
filesSeparator,
|
||||||
|
@ -280,7 +285,8 @@ export const getInputs = (): Inputs => {
|
||||||
outputRenamedFilesAsDeletedAndAdded,
|
outputRenamedFilesAsDeletedAndAdded,
|
||||||
token,
|
token,
|
||||||
apiUrl,
|
apiUrl,
|
||||||
negationPatternsFirst
|
negationPatternsFirst,
|
||||||
|
useRestApi
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fetchDepth) {
|
if (fetchDepth) {
|
||||||
|
|
21
src/main.ts
21
src/main.ts
|
@ -243,10 +243,16 @@ export async function run(): Promise<void> {
|
||||||
})
|
})
|
||||||
core.debug(`Yaml file patterns: ${JSON.stringify(yamlFilePatterns)}`)
|
core.debug(`Yaml file patterns: ${JSON.stringify(yamlFilePatterns)}`)
|
||||||
|
|
||||||
|
if (inputs.useRestApi && !github.context.payload.pull_request?.number) {
|
||||||
|
throw new Error(
|
||||||
|
"Only pull_request* events are supported when using GitHub's REST API."
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
inputs.token &&
|
inputs.token &&
|
||||||
github.context.payload.pull_request?.number &&
|
github.context.payload.pull_request?.number &&
|
||||||
!hasGitDirectory
|
(!hasGitDirectory || inputs.useRestApi)
|
||||||
) {
|
) {
|
||||||
core.info("Using GitHub's REST API to get changed files")
|
core.info("Using GitHub's REST API to get changed files")
|
||||||
const unsupportedInputs: (keyof Inputs)[] = [
|
const unsupportedInputs: (keyof Inputs)[] = [
|
||||||
|
@ -254,12 +260,19 @@ export async function run(): Promise<void> {
|
||||||
'baseSha',
|
'baseSha',
|
||||||
'since',
|
'since',
|
||||||
'until',
|
'until',
|
||||||
|
'path',
|
||||||
|
'quotePath',
|
||||||
|
'diffRelative',
|
||||||
'sinceLastRemoteCommit',
|
'sinceLastRemoteCommit',
|
||||||
'recoverDeletedFiles',
|
'recoverDeletedFiles',
|
||||||
'recoverDeletedFilesToDestination',
|
'recoverDeletedFilesToDestination',
|
||||||
'recoverFiles',
|
'recoverFiles',
|
||||||
|
'recoverFilesSeparator',
|
||||||
'recoverFilesIgnore',
|
'recoverFilesIgnore',
|
||||||
|
'recoverFilesIgnoreSeparator',
|
||||||
'includeAllOldNewRenamedFiles',
|
'includeAllOldNewRenamedFiles',
|
||||||
|
'oldNewSeparator',
|
||||||
|
'oldNewFilesSeparator',
|
||||||
'skipInitialFetch',
|
'skipInitialFetch',
|
||||||
'fetchSubmoduleHistory',
|
'fetchSubmoduleHistory',
|
||||||
'dirNamesDeletedFilesIncludeOnlyDeletedDirs'
|
'dirNamesDeletedFilesIncludeOnlyDeletedDirs'
|
||||||
|
@ -280,10 +293,9 @@ export async function run(): Promise<void> {
|
||||||
} else {
|
} else {
|
||||||
if (!hasGitDirectory) {
|
if (!hasGitDirectory) {
|
||||||
core.info(`Running on a ${github.context.eventName} event...`)
|
core.info(`Running on a ${github.context.eventName} event...`)
|
||||||
core.setFailed(
|
throw new Error(
|
||||||
"Can't find local .git directory. Please run actions/checkout before this action. If you intend to use Github's REST API note that only pull_request* events are supported."
|
"Can't find local .git directory. Please run actions/checkout before this action (Make sure the path specified in the 'path' input is correct). If you intend to use Github's REST API note that only pull_request* events are supported."
|
||||||
)
|
)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
core.info('Using local .git directory')
|
core.info('Using local .git directory')
|
||||||
|
@ -302,5 +314,6 @@ if (!process.env.TESTING) {
|
||||||
// eslint-disable-next-line github/no-then
|
// eslint-disable-next-line github/no-then
|
||||||
run().catch(e => {
|
run().catch(e => {
|
||||||
core.setFailed(e.message || e)
|
core.setFailed(e.message || e)
|
||||||
|
process.exit(1)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue