Skip to content

Commit

Permalink
Updated to setting envs through file (#28)
Browse files Browse the repository at this point in the history
* Updated to setting envs through file

* Taking a peek at the directory

* Maybe another job needs this

* Bump version and fix action

* Does bash work?

* That worked but why?

* I done did the figure out

* What duh?

* Spelling is hard

* Soon
  • Loading branch information
Unthrottled authored Nov 26, 2020
1 parent 78a2939 commit 2241526
Show file tree
Hide file tree
Showing 10 changed files with 266 additions and 3,343 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: echo $GITHUB_ENV
- uses: ./
with:
release-type: non-prod
branch-override: refs/heads/development/v1.3
- run: echo ${VERSION}
- run: echo ${PUBLISH_CHANNEL}
- run: echo ${RELEASE_NOTES}

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
node_modules/

$GITHUB_ENV

# Editors
.vscode/
.idea/
Expand Down
5 changes: 5 additions & 0 deletions constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const GITHUB_ENV_FILE_NAME = process.env.GITHUB_ENV || "$GITHUB_ENV";

module.exports = {
GITHUB_ENV_FILE_NAME,
}
3,540 changes: 217 additions & 3,323 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/sourcemap-register.js
Original file line number Diff line number Diff line change
Expand Up @@ -3847,23 +3847,23 @@ exports.SourceMapConsumer = __webpack_require__(327).SourceMapConsumer;
/***/ ((module) => {

"use strict";
module.exports = require("fs");
module.exports = require("fs");;

/***/ }),

/***/ 282:
/***/ ((module) => {

"use strict";
module.exports = require("module");
module.exports = require("module");;

/***/ }),

/***/ 622:
/***/ ((module) => {

"use strict";
module.exports = require("path");
module.exports = require("path");;

/***/ })

Expand Down
24 changes: 17 additions & 7 deletions envSetup.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
const core = require('@actions/core');
const github = require('@actions/github');
const fs = require('fs');
const {GITHUB_ENV_FILE_NAME} = require('./constants');

function requireNonNull(toBeNotNull, message) {
if(!toBeNotNull) {
if (!toBeNotNull) {
throw Error(message);
}
return toBeNotNull;
}

function getVersionAndPublishChannel(githubRef) {
const [,,channel,version] = githubRef.split('/');
if(!(channel && version)) {
const [, , channel, version] = githubRef.split('/');
if (!(channel && version)) {
throw Error(`Expected the branch name ${githubRef} to match pattern refs/head/<releaseChannel>/<versionNumber>`)
}
return {
Expand All @@ -20,7 +22,7 @@ function getVersionAndPublishChannel(githubRef) {
}

function getReleaseNotes() {
if(github.context.eventName === 'push') {
if (github.context.eventName === 'push') {
const pushPayload = github.context.payload
const commits = pushPayload.commits || []
return commits
Expand All @@ -31,6 +33,8 @@ function getReleaseNotes() {
return `- No release notes`
}



async function setUpNonProd() {
const githubRef = requireNonNull(
core.getInput('branch-override') || process.env.GITHUB_REF,
Expand All @@ -41,13 +45,19 @@ async function setUpNonProd() {
channel
} = getVersionAndPublishChannel(githubRef)
core.info(`Releasing with version '${version}'`)
core.exportVariable('VERSION', version);
core.info(`And on channel '${channel}'`)
core.exportVariable('PUBLISH_CHANNEL', channel);
const releaseNotes = getReleaseNotes()
core.info(`With release notes
${releaseNotes}`)
core.exportVariable('RELEASE_NOTES', releaseNotes)

fs.writeFileSync(GITHUB_ENV_FILE_NAME,
`
VERSION=${version}
PUBLISH_CHANNEL=${channel}
RELEASE_NOTES=${releaseNotes}
`.trim(),
{ encoding: 'utf-8' }
)
}

function setUpProd() {
Expand Down
24 changes: 17 additions & 7 deletions index.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const envSetUp = require('./envSetup');
const fs = require('fs');
const {GITHUB_ENV_FILE_NAME} = require('./constants')

function getInputName(name) {
return `INPUT_${name.replace(/ /g, '_').toUpperCase()}`;
Expand All @@ -19,7 +21,13 @@ describe('Set Environment', function () {

beforeEach(()=>{
process.env.GITHUB_REF = previousGitRef;
})
});

afterEach(() => {
if(fs.existsSync(GITHUB_ENV_FILE_NAME)) {
fs.unlinkSync(GITHUB_ENV_FILE_NAME)
}
});

afterAll(()=>{
process.env.GITHUB_REF = previousGitRef;
Expand Down Expand Up @@ -49,17 +57,19 @@ describe('Set Environment', function () {
process.env.GITHUB_REF = 'refs/heads/development/v1.3'
setInput('branch-override', 'refs/heads/development/v69')
await expect(envSetUp('non-prod')).resolves
.toBeUndefined()
expect(process.env.VERSION).toContain('v69')
expect(process.env.PUBLISH_CHANNEL).toEqual('development')
.toBeUndefined();
const envFile = fs.readFileSync(GITHUB_ENV_FILE_NAME, {encoding: 'utf-8'});
expect(envFile).toContain('VERSION=v69');
expect(envFile).toContain('PUBLISH_CHANNEL=development');
unsetInput('branch-override');
});

test('non-prod should setup correctly', async () => {
process.env.GITHUB_REF = 'refs/heads/development/v1.3'
await expect(envSetUp('non-prod')).resolves
.toBeUndefined()
expect(process.env.VERSION).toContain('v1.3')
expect(process.env.PUBLISH_CHANNEL).toEqual('development')
.toBeUndefined();
const envFile = fs.readFileSync(GITHUB_ENV_FILE_NAME, {encoding: 'utf-8'});
expect(envFile).toContain('VERSION=v1.3');
expect(envFile).toContain('PUBLISH_CHANNEL=development');
});
});
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "waifu-motivator-plugin-release-env-setup-action",
"version": "1.0.0",
"version": "1.1.0",
"description": "Action for setting up the Waifu Motivator Plugin release train",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 2241526

Please sign in to comment.