-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
18 changed files
with
435 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
max_line_length = 140 | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: "build" | ||
|
||
on: [pull_request] | ||
|
||
jobs: | ||
validation: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
|
||
- name: "Config" | ||
run: | | ||
git config --global user.email "git-ci@techinity.com" | ||
git config --global user.name "gitci" | ||
- name: "Install dependencies" | ||
run: npm install | ||
|
||
- name: "Build" | ||
run: npm run build | ||
|
||
- name: "Test" | ||
run: npm run test | ||
|
||
- name: "Lint" | ||
run: npm run lint | ||
|
||
- name: "Commit build output" | ||
run: | | ||
git checkout -B "dist/artifacts-${{github.event.number}}" | ||
git reset ${{github.event.after}} | ||
git add -f dist/ | ||
git commit -m "ci: build distributables" | ||
git push -f https://${{secrets.GH_ACTION_TOKEN}}@github.com/allenevans/set-env.git HEAD:dist/artifacts-${{github.event.number}} | ||
- name: "Check for uncommitted changes" | ||
run: | | ||
git diff --exit-code --stat -- . ':!node_modules' \ | ||
|| (echo "##[error] found changed filces after build." \ | ||
&& exit 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
name: "release" | ||
on: | ||
push: | ||
branches: | ||
- 'master' | ||
|
||
jobs: | ||
validation: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
|
||
- name: "Config" | ||
run: | | ||
echo "Release triggered by ${{github.actor}}" | ||
echo "Commit ${{github.event.commits[0].message}}" | ||
git config --global user.email "git-ci@techinity.com" | ||
git config --global user.name "gitci" | ||
- name: "Install dependencies" | ||
run: npm install | ||
|
||
- name: "Build" | ||
run: npm run build | ||
|
||
- name: "Test" | ||
run: npm run test | ||
|
||
- name: "Commit build artifacts" | ||
if: | | ||
contains(github.event.commits[0].message, '[skip ci]') == false && | ||
contains(github.event.commits[0].message, 'release artifacts') == false | ||
run: | | ||
git add --ignore-errors -f dist/ | ||
git diff-index --quiet HEAD -- || git commit -m 'release artifacts' | ||
- name: "Semantic version" | ||
if: | | ||
contains(github.event.commits[0].message, '[skip ci]') == false && | ||
contains(github.event.commits[0].message, 'release artifacts') == false | ||
env: | ||
GH_TOKEN: ${{secrets.GITHUB_ACTION_TOKEN}} | ||
run: | | ||
npm run release | ||
git status |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package-lock.json | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
*.lcov | ||
|
||
# Dependency directories | ||
node_modules/ | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output | ||
dist/ | ||
*.tgz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
package-lock=false | ||
save-exact |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"arrowParens": "always", | ||
"jsxBracketSameLine": false, | ||
"parser": "typescript", | ||
"printWidth": 140, | ||
"singleQuote": true, | ||
"tabWidth": 2, | ||
"trailingComma": "all", | ||
"useTabs": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"branch": "master", | ||
"plugins": [ | ||
"@semantic-release/commit-analyzer", | ||
"@semantic-release/release-notes-generator", | ||
"@semantic-release/changelog", | ||
"@semantic-release/npm", | ||
"@semantic-release/git" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2019 Allen Evans | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,27 @@ | ||
# set-env | ||
Github action to set environment variables | ||
|
||
Example usage:- | ||
|
||
``` | ||
name: example-pipline | ||
on: [pull_request] | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: changed packages | ||
id: changed_packages | ||
uses: allenevans/set-env@master | ||
- name: Dump steps context | ||
env: | ||
STEPS_CONTEXT: ${{ toJson(steps) }} | ||
run: | | ||
echo "$STEPS_CONTEXT" | ||
echo "scope=${{steps.changed_packages.outputs.scope}}" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name: 'set-env' | ||
description: 'Set environment variables that can be used in other steps' | ||
author: 'Allen Evans' | ||
runs: | ||
using: 'node12' | ||
main: 'dist/set-env.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Contributors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module.exports = { | ||
collectCoverage: true, | ||
moduleFileExtensions: ['ts', 'js', 'json', 'node'], | ||
resetMocks: true, | ||
testMatch: [ | ||
'**/?(*.)spec.ts', | ||
], | ||
testPathIgnorePatterns: [ | ||
'dist/', | ||
'node_modules/', | ||
], | ||
testURL: 'http://localhost/', | ||
transform: { | ||
'^.+\\.tsx?$': 'ts-jest', | ||
}, | ||
verbose: true, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"name": "set-env", | ||
"version": "0.0.1", | ||
"private": true, | ||
"description": "Set environment variables that can be used in other steps", | ||
"main": "dist/set-env.js", | ||
"scripts": { | ||
"build": "webpack --config ./webpack.config.js", | ||
"clean": "rimraf dist/", | ||
"lint": "tslint -c tslint.json --project tsconfig.json", | ||
"prebuild": "npm run clean", | ||
"release": "semantic-release", | ||
"test": "jest --config=jest.config.js --silent" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "/~https://github.com/allenevans/set-env.git" | ||
}, | ||
"keywords": [ | ||
"actions", | ||
"node", | ||
"setup" | ||
], | ||
"author": "Allen Evans", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@actions/core": "1.1.1", | ||
"@semantic-release/changelog": "3.0.4", | ||
"@semantic-release/commit-analyzer": "6.3.0", | ||
"@semantic-release/git": "7.0.16", | ||
"@semantic-release/npm": "5.1.15", | ||
"@semantic-release/release-notes-generator": "7.3.0", | ||
"@types/jest": "24.0.18", | ||
"@types/node": "12.7.5", | ||
"jest": "24.9.0", | ||
"prettier": "1.18.2", | ||
"rimraf": "3.0.0", | ||
"semantic-release": "15.13.24", | ||
"ts-jest": "24.1.0", | ||
"ts-loader": "6.1.2", | ||
"ts-node": "8.4.1", | ||
"tslint": "5.20.0", | ||
"tslint-config-airbnb": "5.11.2", | ||
"typescript": "3.6.3", | ||
"webpack": "4.40.2", | ||
"webpack-cli": "3.3.9" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import * as core from '@actions/core'; | ||
|
||
jest.mock('@actions/core', () => ({ | ||
exportVariable: jest.fn(), | ||
setFailed: jest.fn(), | ||
})); | ||
|
||
describe('set-env', () => { | ||
afterEach(() => { | ||
Object.keys(process.env) | ||
.filter((key) => key.match(/^INPUT_/)) | ||
.forEach((key) => { | ||
delete process.env[key]; | ||
}); | ||
}); | ||
|
||
it('should export all environment variables beginning with INPUT_', () => { | ||
process.env.INPUT_VERSION = '1.2.3'; | ||
|
||
jest.isolateModules(() => require('./main')); | ||
|
||
expect(core.exportVariable).toHaveBeenCalledTimes(1); | ||
expect(core.exportVariable).toHaveBeenCalledWith('VERSION', '1.2.3'); | ||
}); | ||
|
||
it('should export multiple environment variables beginning with INPUT_', () => { | ||
process.env.INPUT_A = '1'; | ||
process.env.INPUT_B = '2'; | ||
process.env.INPUT_C = '3'; | ||
|
||
jest.isolateModules(() => require('./main')); | ||
|
||
expect(core.exportVariable).toHaveBeenCalledTimes(3); | ||
expect(core.exportVariable).toHaveBeenCalledWith('A', '1'); | ||
expect(core.exportVariable).toHaveBeenCalledWith('B', '2'); | ||
expect(core.exportVariable).toHaveBeenCalledWith('C', '3'); | ||
}); | ||
|
||
it('should report exceptions', () => { | ||
(<jest.Mock>core.exportVariable).mockImplementation(() => { | ||
throw new Error('FAIL'); | ||
}); | ||
jest.spyOn(process, 'exit').mockImplementation((code?: number): never => { | ||
throw new Error(`${code}`); | ||
}); | ||
|
||
process.env.INPUT_TEST = 'test'; | ||
|
||
jest.isolateModules(() => expect(() => require('./main')).toThrowError('1')); | ||
|
||
expect(core.setFailed).toHaveBeenCalledTimes(1); | ||
expect(core.setFailed).toHaveBeenCalledWith('FAIL'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import * as core from '@actions/core'; | ||
|
||
(function run() { | ||
try { | ||
Object.keys(process.env) | ||
.filter((key) => /^INPUT_/.test(key)) | ||
.forEach((key) => { | ||
core.exportVariable(key.replace(/^INPUT_/, ''), `${process.env[key]}`); | ||
}); | ||
} catch (error) { | ||
core.setFailed(error.message); | ||
process.exit(1); | ||
} | ||
})(); |
Oops, something went wrong.