Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GITHUB_HEAD_REF if available #27

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,4 @@ Thumbs.db
__tests__/runner/*
/lib/
/dist/
/.idea/
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"format": "prettier --write **/*.ts",
"format-check": "prettier --check **/*.ts",
"lint": "eslint src/**/*.ts",
"package": "ncc build",
"package": "NODE_OPTIONS=--openssl-legacy-provider ncc build",
"test": "jest",
"all": "yarn build && yarn format && yarn lint && yarn package && yarn test"
},
Expand Down
6 changes: 4 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getInput, setFailed, setOutput, info } from '@actions/core';
import { determineVersion } from './determine-version';
import { validateHistoryDepth, checkout, createTag, refExists } from './git';
import { getEnv } from './utils';
import { getEnv, getEnvOrNull } from './utils';

const VERSION_PLACEHOLDER = /{VERSION}/g;

Expand All @@ -14,7 +14,9 @@ async function run(): Promise<void> {
info(`Previous version: ${previousVersion}`);
setOutput('previous-version', previousVersion);

await checkout(getEnv('GITHUB_REF'));
const checkoutRef = getEnvOrNull('GITHUB_HEAD_REF') || getEnv('GITHUB_REF');

await checkout(checkoutRef);

let currentVersion = await determineVersion();

Expand Down
10 changes: 9 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
export function getEnv(name: string): string {
export function getEnvOrNull(name: string): string | null {
let value = process.env[name];
if (typeof value === 'string') {
return value;
}
return null;
}

export function getEnv(name: string): string {
let value = getEnvOrNull(name);
if (typeof value === 'string') {
return value;
}

throw new Error(`Missing environment variable ${name}`);
}
Loading