only error on actual attempt at using bodyFromFile and reorder a bit for tests

This commit is contained in:
Jacob Bolda 2020-02-05 22:46:40 -06:00
parent 76860a04af
commit c06331b12c
No known key found for this signature in database
GPG Key ID: 22CE5B1A2BD487F7
2 changed files with 22 additions and 16 deletions

19
dist/index.js vendored
View File

@ -7863,16 +7863,19 @@ async function run() {
const tag = tagName.replace('refs/tags/', '');
const releaseName = core.getInput('release_name', { required: true }).replace('refs/tags/', '');
const body = core.getInput('body', { required: false });
const bodyFromFile = core.getInput('bodyFromFile', { required: false });
let bodyFile = null;
try {
bodyFile = fs.readFileSync(bodyFromFile, { encoding: 'utf8' });
} catch (error) {
core.setFailed(error.message);
}
const draft = core.getInput('draft', { required: false }) === 'true';
const prerelease = core.getInput('prerelease', { required: false }) === 'true';
const bodyFromFile = core.getInput('bodyFromFile', { required: false });
let bodyFileContent = null;
if (bodyFromFile !== '' && !!bodyFromFile) {
try {
bodyFileContent = fs.readFileSync(bodyFromFile, { encoding: 'utf8' });
} catch (error) {
core.setFailed(error.message);
}
}
// Create a release
// API Documentation: https://developer.github.com/v3/repos/releases/#create-a-release
// Octokit Documentation: https://octokit.github.io/rest.js/#octokit-routes-repos-create-release
@ -7881,7 +7884,7 @@ async function run() {
repo,
tag_name: tag,
name: releaseName,
body: bodyFile || body,
body: bodyFileContent || body,
draft,
prerelease
});

View File

@ -17,16 +17,19 @@ async function run() {
const tag = tagName.replace('refs/tags/', '');
const releaseName = core.getInput('release_name', { required: true }).replace('refs/tags/', '');
const body = core.getInput('body', { required: false });
const bodyFromFile = core.getInput('bodyFromFile', { required: false });
let bodyFile = null;
try {
bodyFile = fs.readFileSync(bodyFromFile, { encoding: 'utf8' });
} catch (error) {
core.setFailed(error.message);
}
const draft = core.getInput('draft', { required: false }) === 'true';
const prerelease = core.getInput('prerelease', { required: false }) === 'true';
const bodyFromFile = core.getInput('bodyFromFile', { required: false });
let bodyFileContent = null;
if (bodyFromFile !== '' && !!bodyFromFile) {
try {
bodyFileContent = fs.readFileSync(bodyFromFile, { encoding: 'utf8' });
} catch (error) {
core.setFailed(error.message);
}
}
// Create a release
// API Documentation: https://developer.github.com/v3/repos/releases/#create-a-release
// Octokit Documentation: https://octokit.github.io/rest.js/#octokit-routes-repos-create-release
@ -35,7 +38,7 @@ async function run() {
repo,
tag_name: tag,
name: releaseName,
body: bodyFile || body,
body: bodyFileContent || body,
draft,
prerelease
});