Skip to content

Commit

Permalink
PTFE-1271 handle proper sha on pull_request events
Browse files Browse the repository at this point in the history
  • Loading branch information
tcarmet committed Dec 22, 2023
1 parent 1a7f777 commit 02d194d
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 16 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/test-pull-request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
on: pull_request

name: Test pull request

jobs:
tests:
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v4
- name: create file to upload
run: |
mkdir -p artifacts
echo "Hello world" > artifacts/file1.txt
- name: Push all files
uses: ./
id: artifacts
with:
url: ${{ vars.ARTIFACTS_URL }}
user: ${{ secrets.ARTIFACTS_USER }}
password: ${{ secrets.ARTIFACTS_PASSWORD }}
source: ./artifacts
method: upload
- name: Test results
run: |
SHA=${{ github.event.pull_request.head.sha }}
SHORTSHA=${SHA::10}
# We expect SHORTSHA to be in the name of the artifact
if [[ ${ARTIFACTS_NAME} != *${SHORTSHA}* ]]; then
echo "Artifact name ${ARTIFACT_NAME} does not contain the short SHA"
exit 1
fi
env:
ARTIFACTS_NAME: ${{ steps.artifacts.outputs.name }}
22 changes: 14 additions & 8 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.

19 changes: 12 additions & 7 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,18 @@ export async function artifactsIndexRequestRetry(
export async function getCommitSha1(revspec: string): Promise<string> {
let sha = ''
try {
const commits = await git.log({
fs,
dir: process.cwd(),
ref: revspec,
depth: 1
})
sha = commits[0].oid
if (context.eventName === 'pull_request') {
sha = context.payload.pull_request?.head?.sha as string
}
else {
const commits = await git.log({
fs,
dir: process.cwd(),
ref: revspec,
depth: 1
})
sha = commits[0].oid
}
} catch (e) {
core.debug('getCommitSha1 failed, fallback to context.sha')
sha = context.sha
Expand Down

0 comments on commit 02d194d

Please sign in to comment.