Skip to content

Commit

Permalink
fix: update test to include push event (#1173)
Browse files Browse the repository at this point in the history
Co-authored-by: tj-actions[bot] <109116665+tj-actions-bot@users.noreply.github.com>
Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
3 people authored May 25, 2023
1 parent 30e1bb0 commit abef388
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 86 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:

build:
runs-on: ubuntu-latest
if: github.event_name != 'push'
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -50,6 +49,7 @@ jobs:
- name: Run eslint on changed files
uses: tj-actions/eslint-changed-files@v18
if: github.event_name != 'push'
with:
token: ${{ secrets.PAT_TOKEN }}
config_path: ".eslintrc.json"
Expand All @@ -62,21 +62,22 @@ jobs:
- name: Verify Changed files
uses: tj-actions/verify-changed-files@v14
id: changed_files
if: github.event_name != 'push'
with:
files: |
src
dist
- name: Commit files
if: steps.changed_files.outputs.files_changed == 'true'
if: steps.changed_files.outputs.files_changed == 'true' && github.event_name != 'push'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add src dist
git commit -m "Added missing changes and modified dist assets."
- name: Push changes
if: steps.changed_files.outputs.files_changed == 'true'
if: steps.changed_files.outputs.files_changed == 'true' && github.event_name == 'pull_request'
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.PAT_TOKEN }}
Expand Down Expand Up @@ -1160,7 +1161,7 @@ jobs:
main-branch-name: ${{ steps.branch-name.outputs.base_ref_branch }}
workflow-id: 'test.yml'
- name: Run changed-files with a custom base sha
if: github.event_name == 'pull_request' && github.event.action != 'closed' && matrix.fetch-depth == 0
if: github.event_name != 'push' && github.event.action != 'closed' && matrix.fetch-depth == 0
id: changed-files-custom-base-sha
uses: ./
with:
Expand Down
74 changes: 37 additions & 37 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

30 changes: 15 additions & 15 deletions src/commitSha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {Inputs} from './inputs'
import {
canDiffCommits,
getHeadSha,
getParentHeadSha,
getParentSha,
getPreviousGitTag,
gitFetch,
gitFetchSubmodules,
Expand Down Expand Up @@ -74,7 +74,7 @@ export const getSHAForPushEvent = async (
gitExtraArgs: string[],
isTag: boolean
): Promise<DiffResult> => {
let targetBranch = env.GITHUB_REFNAME
let targetBranch = env.GITHUB_REF_NAME
const currentBranch = targetBranch
let initialCommit = false

Expand Down Expand Up @@ -174,33 +174,33 @@ export const getSHAForPushEvent = async (
previousSha = sha
targetBranch = tag
} else {
if (inputs.sinceLastRemoteCommit) {
core.debug('Getting previous SHA for last remote commit...')

if (env.GITHUB_EVENT_FORCED === 'false' || !env.GITHUB_EVENT_FORCED) {
previousSha = env.GITHUB_EVENT_BEFORE
} else {
previousSha = await getParentHeadSha({cwd: workingDirectory})
}
core.debug('Getting previous SHA for last remote commit...')
if (env.GITHUB_EVENT_FORCED === 'false' || !env.GITHUB_EVENT_FORCED) {
previousSha = env.GITHUB_EVENT_BEFORE
} else {
core.debug('Getting previous SHA for last commit...')
previousSha = await getParentHeadSha({cwd: workingDirectory})
previousSha = await getParentSha({
cwd: workingDirectory
})
}

if (
!previousSha ||
previousSha === '0000000000000000000000000000000000000000'
) {
previousSha = await getParentHeadSha({cwd: workingDirectory})
previousSha = await getParentSha({
cwd: workingDirectory
})
}

if (previousSha === currentSha) {
if (!(await getParentHeadSha({cwd: workingDirectory}))) {
if (!(await getParentSha({cwd: workingDirectory}))) {
core.warning('Initial commit detected no previous commit found.')
initialCommit = true
previousSha = currentSha
} else {
previousSha = await getParentHeadSha({cwd: workingDirectory})
previousSha = await getParentSha({
cwd: workingDirectory
})
}
} else {
if (!previousSha) {
Expand Down
5 changes: 2 additions & 3 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export type Env = {
GITHUB_EVENT_PULL_REQUEST_HEAD_REF: string
GITHUB_EVENT_PULL_REQUEST_BASE_REF: string
GITHUB_EVENT_BEFORE: string
GITHUB_REFNAME: string
GITHUB_REF_NAME: string
GITHUB_REF: string
GITHUB_EVENT_BASE_REF: string
GITHUB_EVENT_HEAD_REPO_FORK: string
Expand Down Expand Up @@ -41,7 +41,6 @@ export const getEnv = async (): Promise<Env> => {
if (eventPath) {
eventJson = JSON.parse(await fs.readFile(eventPath, {encoding: 'utf8'}))
}

core.debug(`Event: ${JSON.stringify(eventJson, null, 2)}`)

return {
Expand All @@ -53,7 +52,7 @@ export const getEnv = async (): Promise<Env> => {
GITHUB_EVENT_PULL_REQUEST_NUMBER: eventJson.pull_request?.number || '',
GITHUB_EVENT_PULL_REQUEST_BASE_SHA: eventJson.pull_request?.base?.sha || '',
GITHUB_EVENT_FORCED: eventJson.forced || '',
GITHUB_REFNAME: process.env.GITHUB_REFNAME || '',
GITHUB_REF_NAME: process.env.GITHUB_REF_NAME || '',
GITHUB_REF: process.env.GITHUB_REF || '',
GITHUB_WORKSPACE: process.env.GITHUB_WORKSPACE || ''
}
Expand Down
Loading

0 comments on commit abef388

Please sign in to comment.