Skip to content

Commit

Permalink
action.cjs: simplify changed-files step
Browse files Browse the repository at this point in the history
  • Loading branch information
thypon committed May 24, 2024
1 parent ad787bb commit 1a22fda
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
12 changes: 9 additions & 3 deletions action.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ function hashFiles (filename) {
return fs.existsSync(filename)
}

module.exports = async ({ github, context, inputs, steps, actionPath, core }) => {
module.exports = async ({ github, context, inputs, actionPath, core }) => {
// changed-files steps
let changedFiles = []

// reviewdog-enabled-pr steps
let reviewdogEnabledPr = false
if (inputs.enabled === 'true' && inputs.baseline_scan_only !== 'false' && steps['changed-files'].outputs.all_changed_files !== '' && process.env.GITHUB_EVENT_NAME === 'pull_request' && context.payload.pull_request.draft === false && context.actor !== 'dependabot[bot]') {
if (inputs.enabled === 'true' && inputs.baseline_scan_only !== 'false' && process.env.GITHUB_EVENT_NAME === 'pull_request' && context.payload.pull_request.draft === false && context.actor !== 'dependabot[bot]') {
const { default: pullRequestChangedFiles } = await import(`${actionPath}/src/pullRequestChangedFiles.js`)

reviewdogEnabledPr = true
changedFiles = pullRequestChangedFiles({ github, owner: context.repo.owner, name: context.repo.repo, prnumber: context.payload.pull_request.number })
}
// reviewdog-enabled-full steps
let reviewdogEnabledFull = false
Expand All @@ -23,7 +29,7 @@ module.exports = async ({ github, context, inputs, steps, actionPath, core }) =>
// Write changed files to file
if (reviewdogEnabledPr) {
const fs = require('fs')
fs.writeFileSync(`${actionPath}/assets/all_changed_files.txt`, steps['changed-files'].outputs.all_changed_files)
fs.writeFileSync(`${actionPath}/assets/all_changed_files.txt`, changedFiles.join('\0'))
}
// comments-before steps
let commentsBefore = null
Expand Down
11 changes: 2 additions & 9 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,8 @@ outputs:
runs:
using: 'composite'
steps:
- name: Get changed files
if: ${{ inputs.enabled == 'true' && github.event_name == 'pull_request' }}
id: changed-files
uses: tj-actions/changed-files@0874344d6ebbaa00a27da73276ae7162fadcaf69 # v44.3.0
with:
separator: '\0'
- name: Store reviewdog enabled for PR
if: ${{ inputs.enabled == 'true' && inputs.baseline_scan_only != 'false' && steps.changed-files.outputs.all_changed_files != '' && github.event_name == 'pull_request' && github.event.pull_request.draft == false && github.actor != 'dependabot[bot]' }}
if: ${{ inputs.enabled == 'true' && inputs.baseline_scan_only != 'false' && github.event_name == 'pull_request' && github.event.pull_request.draft == false && github.actor != 'dependabot[bot]' }}
id: reviewdog-enabled-pr
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
Expand Down Expand Up @@ -146,10 +140,9 @@ runs:
script: |
const actionPath = '${{ github.action_path }}'
const inputs = ${{ toJson(inputs) }}
const steps = ${{ toJson(steps) }}
const script = require(`${actionPath}/action.cjs`)
await script({github, context, inputs, steps, actionPath, core})
await script({github, context, inputs, actionPath, core})
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
Expand Down

0 comments on commit 1a22fda

Please sign in to comment.