Skip to content

Commit

Permalink
Merge pull request #1 from EmergeTools/rb-fixBaseSha
Browse files Browse the repository at this point in the history
Update to pass baseSha to upload endpoint.
  • Loading branch information
rbro112 authored Dec 8, 2021
2 parents ebe92ef + 41cc031 commit 6a0d0b6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Add the API key to your secrets in your repository. **Do not leave this key in p
### Incorporate in your workflow

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

```yaml
name: Your workflow
Expand All @@ -45,7 +45,7 @@ jobs:
- name: Generate Android release bundle
run: ./gradlew bundleRelease
- name: Upload artifact to Emerge
uses: EmergeTools/[email protected].0
uses: EmergeTools/[email protected].1
with:
artifact_path: ./app/build/outputs/bundle/release/app-release.aab
emerge_api_key: ${{ secrets.EMERGE_API_KEY }}
Expand Down
25 changes: 20 additions & 5 deletions src/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import { getPRNumber, getAbsoluteArtifactPath } from './utils';
const core = require('@actions/core');
const github = require('@actions/github');

// The sha set for `before` on push events if the first push to a commit. This should not ever be the case if
// pushing to main unless it's the initial commit.
const DEFAULT_PUSH_BEFORE_SHA = '0000000000000000000000000000000000000000';

function getInputs(): UploadInputs {
core.info('Parsing inputs...');

Expand All @@ -23,21 +27,31 @@ function getInputs(): UploadInputs {
// of the commit that triggered this action.
// Therefore, on a PR we need to explicitly get the head sha
let sha;
let baseSha;
let branchName;
const eventFile = fs.readFileSync(process.env.GITHUB_EVENT_PATH ?? '', {
encoding: 'utf8',
});
const eventFileJson = JSON.parse(eventFile);
if (process.env.GITHUB_EVENT_NAME === 'pull_request') {
const eventFile = fs.readFileSync(process.env.GITHUB_EVENT_PATH ?? '', {
encoding: 'utf8',
});
const eventFileJson = JSON.parse(eventFile);
sha = eventFileJson?.pull_request?.head?.sha ?? process.env.GITHUB_SHA ?? '';
baseSha = eventFileJson?.pull_request?.base?.sha ?? '';
branchName = process.env.GITHUB_HEAD_REF ?? '';
} else {
} else if (process.env.GITHUB_EVENT_NAME === 'push') {
sha = process.env.GITHUB_SHA ?? '';
// Get the SHA of the previous commit, which will be the baseSha in the case of a push event.
baseSha = eventFileJson?.before ?? '';
if (eventFileJson?.baseRef === null || baseSha === DEFAULT_PUSH_BEFORE_SHA) {
baseSha = '';
}

const ref = process.env.GITHUB_REF ?? '';
if (ref !== '') {
const refSplits = ref.split('/');
branchName = refSplits[refSplits.length - 1];
}
} else {
core.setFailed(`Unsupported action trigger: ${process.env.GITHUB_EVENT_NAME}`);
}

if (sha === '') {
Expand Down Expand Up @@ -78,6 +92,7 @@ function getInputs(): UploadInputs {
filename,
emergeApiKey,
sha,
baseSha,
repoName,
prNumber,
buildType,
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type UploadInputs = {
filename: string
emergeApiKey: string
sha: string
baseSha: string
repoName: string

// Required for PRs
Expand Down
1 change: 1 addition & 0 deletions src/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ async function run(): Promise<void> {
prNumber: inputs.prNumber,
branch: inputs.branchName,
sha: inputs.sha,
baseSha: inputs.baseSha,
repoName: inputs.repoName,
buildType: inputs.buildType,
};
Expand Down

0 comments on commit 6a0d0b6

Please sign in to comment.