Skip to content

Commit 6a0d0b6

Browse files
authored
Merge pull request #1 from EmergeTools/rb-fixBaseSha
Update to pass baseSha to upload endpoint.
2 parents ebe92ef + 41cc031 commit 6a0d0b6

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Add the API key to your secrets in your repository. **Do not leave this key in p
2626
### Incorporate in your workflow
2727

2828
Build your artifact in a step before the Emerge upload action. Pass the generated artifact's path as the `artifact_path`
29-
argument, and your Emerge API key secret as the `emerge_api_key` argument
29+
argument, and your Emerge API key secret as the `emerge_api_key` argument:
3030

3131
```yaml
3232
name: Your workflow
@@ -45,7 +45,7 @@ jobs:
4545
- name: Generate Android release bundle
4646
run: ./gradlew bundleRelease
4747
- name: Upload artifact to Emerge
48-
uses: EmergeTools/[email protected].0
48+
uses: EmergeTools/[email protected].1
4949
with:
5050
artifact_path: ./app/build/outputs/bundle/release/app-release.aab
5151
emerge_api_key: ${{ secrets.EMERGE_API_KEY }}

src/inputs.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import { getPRNumber, getAbsoluteArtifactPath } from './utils';
66
const core = require('@actions/core');
77
const github = require('@actions/github');
88

9+
// The sha set for `before` on push events if the first push to a commit. This should not ever be the case if
10+
// pushing to main unless it's the initial commit.
11+
const DEFAULT_PUSH_BEFORE_SHA = '0000000000000000000000000000000000000000';
12+
913
function getInputs(): UploadInputs {
1014
core.info('Parsing inputs...');
1115

@@ -23,21 +27,31 @@ function getInputs(): UploadInputs {
2327
// of the commit that triggered this action.
2428
// Therefore, on a PR we need to explicitly get the head sha
2529
let sha;
30+
let baseSha;
2631
let branchName;
32+
const eventFile = fs.readFileSync(process.env.GITHUB_EVENT_PATH ?? '', {
33+
encoding: 'utf8',
34+
});
35+
const eventFileJson = JSON.parse(eventFile);
2736
if (process.env.GITHUB_EVENT_NAME === 'pull_request') {
28-
const eventFile = fs.readFileSync(process.env.GITHUB_EVENT_PATH ?? '', {
29-
encoding: 'utf8',
30-
});
31-
const eventFileJson = JSON.parse(eventFile);
3237
sha = eventFileJson?.pull_request?.head?.sha ?? process.env.GITHUB_SHA ?? '';
38+
baseSha = eventFileJson?.pull_request?.base?.sha ?? '';
3339
branchName = process.env.GITHUB_HEAD_REF ?? '';
34-
} else {
40+
} else if (process.env.GITHUB_EVENT_NAME === 'push') {
3541
sha = process.env.GITHUB_SHA ?? '';
42+
// Get the SHA of the previous commit, which will be the baseSha in the case of a push event.
43+
baseSha = eventFileJson?.before ?? '';
44+
if (eventFileJson?.baseRef === null || baseSha === DEFAULT_PUSH_BEFORE_SHA) {
45+
baseSha = '';
46+
}
47+
3648
const ref = process.env.GITHUB_REF ?? '';
3749
if (ref !== '') {
3850
const refSplits = ref.split('/');
3951
branchName = refSplits[refSplits.length - 1];
4052
}
53+
} else {
54+
core.setFailed(`Unsupported action trigger: ${process.env.GITHUB_EVENT_NAME}`);
4155
}
4256

4357
if (sha === '') {
@@ -78,6 +92,7 @@ function getInputs(): UploadInputs {
7892
filename,
7993
emergeApiKey,
8094
sha,
95+
baseSha,
8196
repoName,
8297
prNumber,
8398
buildType,

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export type UploadInputs = {
55
filename: string
66
emergeApiKey: string
77
sha: string
8+
baseSha: string
89
repoName: string
910

1011
// Required for PRs

src/upload.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ async function run(): Promise<void> {
1212
prNumber: inputs.prNumber,
1313
branch: inputs.branchName,
1414
sha: inputs.sha,
15+
baseSha: inputs.baseSha,
1516
repoName: inputs.repoName,
1617
buildType: inputs.buildType,
1718
};

0 commit comments

Comments
 (0)