-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 93ce504
Showing
11 changed files
with
4,591 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,30 @@ | ||
name: Code Deployment | ||
on: | ||
push: | ||
branches: | ||
- master | ||
jobs: | ||
release: | ||
name: Release | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
persist-credentials: false | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 18 | ||
- name: Install dependencies | ||
run: | | ||
npm install | ||
npm i --no-save @vercel/ncc semantic-release @semantic-release/changelog @semantic-release/git @semantic-release/exec conventional-changelog-conventionalcommits | ||
- name: Release | ||
run: | | ||
npx ncc build index.js | ||
git add --force dist/ | ||
git commit -m'chore(release) distribution files [skip ci] | ||
git push origin master | ||
npx semantic-release |
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 @@ | ||
node_modules | ||
dist |
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 @@ | ||
{ | ||
"tabWidth": 2, | ||
"printWidth": 100, | ||
"singleQuote": true, | ||
"trailingComma": "es5" | ||
} |
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,18 @@ | ||
name: "Hello World" | ||
description: "Greet someone and record the time" | ||
inputs: | ||
regexReplaces: | ||
description: "Stringified array Javascript replace patterns." | ||
required: false | ||
default: '[["feature\/","dev-"],["release\/","qa-"]]' | ||
environmentMap: | ||
description: "Stringified object where the keys are branch names and the values is an array of environments to map to." | ||
default: '{}' | ||
outputs: | ||
environment: | ||
description: "The environment to deploy to based on the regex replacements." | ||
environmentMatrix: | ||
description: "Matrix containing mapped environments." | ||
runs: | ||
using: "node16" | ||
main: "dist/index.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,22 @@ | ||
const core = require('@actions/core'); | ||
const getVariables = require('./lib/util/variables.util'); | ||
const translateBranch = require('./lib/branchTranslation'); | ||
|
||
(async () => { | ||
try { | ||
const variables = getVariables(); | ||
// TODO Validate | ||
|
||
// Get current branch | ||
const currentBranch = process.env.GITHUB_REF.split('refs/heads/')[1]; | ||
const translatedCurrentBranch = translateBranch(currentBranch, variables.regexReplaces); | ||
|
||
core.setOutput('environment', translatedCurrentBranch); | ||
|
||
const matrix = variables.environmentMap[translatedCurrentBranch] || [translatedCurrentBranch]; | ||
|
||
core.setOutput('environmentMatrix', JSON.stringify(matrix)); | ||
} catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
})(); |
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 @@ | ||
module.exports = (branch, regexReplacePatterns) => { | ||
let translatedBranch = branch; | ||
|
||
regexReplacePatterns.forEach(([pattern, replacement]) => { | ||
const regex = new RegExp(pattern, 'g'); | ||
translatedBranch = translatedBranch.replace(regex, replacement); | ||
}); | ||
|
||
return translatedBranch; | ||
}; |
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,29 @@ | ||
const core = require('@actions/core'); | ||
const yaml = require('yaml'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
module.exports = () => { | ||
let actionDotYaml; | ||
const variables = {}; | ||
|
||
try { | ||
actionDotYaml = fs.readFileSync(path.join(__dirname, '../../action.yml'), 'utf8'); | ||
} catch (fsError) { | ||
console.error(fsError); | ||
throw new Error( | ||
"Error while trying to parse the 'action.yml' file in the root of the directory. Make sure it exists." | ||
); | ||
} | ||
|
||
const parsedActionDotYaml = yaml.parse(actionDotYaml); | ||
Object.keys(parsedActionDotYaml.inputs).forEach((inputVariable) => { | ||
try { | ||
variables[inputVariable] = JSON.parse(core.getInput(inputVariable)); | ||
} catch (error) { | ||
variables[inputVariable] = core.getInput(inputVariable); | ||
} | ||
}); | ||
|
||
return variables; | ||
}; |
Oops, something went wrong.