-
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
1 parent
fa39a41
commit 8e8180f
Showing
147 changed files
with
27,538 additions
and
27,538 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
node_modules/ | ||
build/ | ||
dist/ | ||
.git/ | ||
node_modules/ | ||
build/ | ||
dist/ | ||
.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 |
---|---|---|
@@ -1,17 +1,17 @@ | ||
[flake8] | ||
max-line-length = 120 | ||
exclude = | ||
.git, | ||
__pycache__, | ||
build, | ||
dist, | ||
.venv, | ||
notes, | ||
experiment.py | ||
ignore = | ||
E203, | ||
E266, | ||
E501, | ||
W503 | ||
per-file-ignores = | ||
[flake8] | ||
max-line-length = 120 | ||
exclude = | ||
.git, | ||
__pycache__, | ||
build, | ||
dist, | ||
.venv, | ||
notes, | ||
experiment.py | ||
ignore = | ||
E203, | ||
E266, | ||
E501, | ||
W503 | ||
per-file-ignores = | ||
__init__.py: F401 |
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,6 +1,6 @@ | ||
name: "Load Environment Variables" | ||
description: "Sets environment variables such as dev environment." | ||
|
||
runs: | ||
using: "node20" | ||
main: "load-env-variables.js" | ||
name: "Load Environment Variables" | ||
description: "Sets environment variables such as dev environment." | ||
|
||
runs: | ||
using: "node20" | ||
main: "load-env-variables.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 |
---|---|---|
@@ -1,42 +1,42 @@ | ||
const core = require("@actions/core"); | ||
const github = require("@actions/github"); | ||
const fs = require("fs"); | ||
|
||
async function loadEnvironmentVariables() { | ||
try { | ||
const eventName = github.context.eventName; | ||
let refName; | ||
|
||
if (eventName === "pull_request") { | ||
refName = github.context.payload.pull_request.base.ref; | ||
} else if (eventName === "push") { | ||
const refParts = github.context.ref.split("/"); | ||
refName = refParts.length > 2 ? refParts[2] : ""; | ||
} else { | ||
throw new Error( | ||
"Unsupported GitHub event. Only pull_request and push events are supported." | ||
); | ||
} | ||
|
||
if (!["dev", "stage", "prod"].includes(refName)) { | ||
throw new Error( | ||
`The branch ${refName} does not map to a supported environment.` | ||
); | ||
} | ||
|
||
const envName = refName.replace(/\//g, "-"); | ||
core.exportVariable("ENV_NAME", envName); | ||
|
||
console.log(`Environment variables set for environment: ${envName}`); | ||
} catch (error) { | ||
core.setFailed(`Action failed with error: ${error}`); | ||
} | ||
} | ||
|
||
if (require.main === module) { | ||
loadEnvironmentVariables(); | ||
} | ||
|
||
module.exports = { | ||
loadEnvironmentVariables, | ||
}; | ||
const core = require("@actions/core"); | ||
const github = require("@actions/github"); | ||
const fs = require("fs"); | ||
|
||
async function loadEnvironmentVariables() { | ||
try { | ||
const eventName = github.context.eventName; | ||
let refName; | ||
|
||
if (eventName === "pull_request") { | ||
refName = github.context.payload.pull_request.base.ref; | ||
} else if (eventName === "push") { | ||
const refParts = github.context.ref.split("/"); | ||
refName = refParts.length > 2 ? refParts[2] : ""; | ||
} else { | ||
throw new Error( | ||
"Unsupported GitHub event. Only pull_request and push events are supported." | ||
); | ||
} | ||
|
||
if (!["dev", "stage", "prod"].includes(refName)) { | ||
throw new Error( | ||
`The branch ${refName} does not map to a supported environment.` | ||
); | ||
} | ||
|
||
const envName = refName.replace(/\//g, "-"); | ||
core.exportVariable("ENV_NAME", envName); | ||
|
||
console.log(`Environment variables set for environment: ${envName}`); | ||
} catch (error) { | ||
core.setFailed(`Action failed with error: ${error}`); | ||
} | ||
} | ||
|
||
if (require.main === module) { | ||
loadEnvironmentVariables(); | ||
} | ||
|
||
module.exports = { | ||
loadEnvironmentVariables, | ||
}; |
148 changes: 74 additions & 74 deletions
148
.github/actions/set-aws-credentials/__tests__/set-aws-credentials.test.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 |
---|---|---|
@@ -1,74 +1,74 @@ | ||
jest.mock('@actions/core'); | ||
const source_path = '../set-aws-credentials'; | ||
const { it } = require('@jest/globals'); | ||
const { setAwsCredentials } = require(source_path); | ||
|
||
const core = require('@actions/core'); | ||
|
||
describe('setAwsCredentials', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
|
||
core.getInput.mockImplementation((name) => { | ||
switch (name) { | ||
case 'ENVIRONMENT_NAME': | ||
return process.env['INPUT_ENVIRONMENT_NAME']; | ||
case 'DEV_AWS_ACCESS_KEY_ID': | ||
return 'devAccessKeyId'; | ||
case 'DEV_AWS_SECRET_ACCESS_KEY': | ||
return 'devSecretAccessKey'; | ||
case 'PROD_AWS_ACCESS_KEY_ID': | ||
return 'prodAccessKeyId'; | ||
case 'PROD_AWS_SECRET_ACCESS_KEY': | ||
return 'prodSecretAccessKey'; | ||
case 'STAGE_AWS_ACCESS_KEY_ID': | ||
return 'stageAccessKeyId'; | ||
case 'STAGE_AWS_SECRET_ACCESS_KEY': | ||
return 'stageSecretAccessKey'; | ||
default: | ||
return ''; | ||
} | ||
}); | ||
}); | ||
|
||
it('should set AWS credentials for dev environment', () => { | ||
process.env['INPUT_ENVIRONMENT_NAME'] = 'dev'; | ||
|
||
setAwsCredentials(); | ||
|
||
expect(core.setSecret).toHaveBeenCalledWith('devAccessKeyId'); | ||
expect(core.setSecret).toHaveBeenCalledWith('devSecretAccessKey'); | ||
expect(core.exportVariable).toHaveBeenCalledWith('AWS_ACCESS_KEY_ID', 'devAccessKeyId'); | ||
expect(core.exportVariable).toHaveBeenCalledWith('AWS_SECRET_ACCESS_KEY', 'devSecretAccessKey'); | ||
}); | ||
|
||
it('should set AWS credentials for prod environment', () => { | ||
process.env['INPUT_ENVIRONMENT_NAME'] = 'prod'; | ||
|
||
setAwsCredentials(); | ||
|
||
expect(core.setSecret).toHaveBeenCalledWith('prodAccessKeyId'); | ||
expect(core.setSecret).toHaveBeenCalledWith('prodSecretAccessKey'); | ||
expect(core.exportVariable).toHaveBeenCalledWith('AWS_ACCESS_KEY_ID', 'prodAccessKeyId'); | ||
expect(core.exportVariable).toHaveBeenCalledWith('AWS_SECRET_ACCESS_KEY', 'prodSecretAccessKey'); | ||
}); | ||
|
||
it('should set AWS credentials for stage environment', () => { | ||
process.env['INPUT_ENVIRONMENT_NAME'] = 'stage'; | ||
|
||
setAwsCredentials(); | ||
|
||
expect(core.setSecret).toHaveBeenCalledWith('stageAccessKeyId'); | ||
expect(core.setSecret).toHaveBeenCalledWith('stageSecretAccessKey'); | ||
expect(core.exportVariable).toHaveBeenCalledWith('AWS_ACCESS_KEY_ID', 'stageAccessKeyId'); | ||
expect(core.exportVariable).toHaveBeenCalledWith('AWS_SECRET_ACCESS_KEY', 'stageSecretAccessKey'); | ||
}); | ||
|
||
it('should set core.setFailed when environment name is not supported', () => { | ||
process.env['INPUT_ENVIRONMENT_NAME'] = 'unsupported'; | ||
|
||
setAwsCredentials(); | ||
|
||
expect(core.setFailed).toHaveBeenCalledWith('Unsupported environment name: unsupported'); | ||
}); | ||
}); | ||
jest.mock('@actions/core'); | ||
const source_path = '../set-aws-credentials'; | ||
const { it } = require('@jest/globals'); | ||
const { setAwsCredentials } = require(source_path); | ||
|
||
const core = require('@actions/core'); | ||
|
||
describe('setAwsCredentials', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
|
||
core.getInput.mockImplementation((name) => { | ||
switch (name) { | ||
case 'ENVIRONMENT_NAME': | ||
return process.env['INPUT_ENVIRONMENT_NAME']; | ||
case 'DEV_AWS_ACCESS_KEY_ID': | ||
return 'devAccessKeyId'; | ||
case 'DEV_AWS_SECRET_ACCESS_KEY': | ||
return 'devSecretAccessKey'; | ||
case 'PROD_AWS_ACCESS_KEY_ID': | ||
return 'prodAccessKeyId'; | ||
case 'PROD_AWS_SECRET_ACCESS_KEY': | ||
return 'prodSecretAccessKey'; | ||
case 'STAGE_AWS_ACCESS_KEY_ID': | ||
return 'stageAccessKeyId'; | ||
case 'STAGE_AWS_SECRET_ACCESS_KEY': | ||
return 'stageSecretAccessKey'; | ||
default: | ||
return ''; | ||
} | ||
}); | ||
}); | ||
|
||
it('should set AWS credentials for dev environment', () => { | ||
process.env['INPUT_ENVIRONMENT_NAME'] = 'dev'; | ||
|
||
setAwsCredentials(); | ||
|
||
expect(core.setSecret).toHaveBeenCalledWith('devAccessKeyId'); | ||
expect(core.setSecret).toHaveBeenCalledWith('devSecretAccessKey'); | ||
expect(core.exportVariable).toHaveBeenCalledWith('AWS_ACCESS_KEY_ID', 'devAccessKeyId'); | ||
expect(core.exportVariable).toHaveBeenCalledWith('AWS_SECRET_ACCESS_KEY', 'devSecretAccessKey'); | ||
}); | ||
|
||
it('should set AWS credentials for prod environment', () => { | ||
process.env['INPUT_ENVIRONMENT_NAME'] = 'prod'; | ||
|
||
setAwsCredentials(); | ||
|
||
expect(core.setSecret).toHaveBeenCalledWith('prodAccessKeyId'); | ||
expect(core.setSecret).toHaveBeenCalledWith('prodSecretAccessKey'); | ||
expect(core.exportVariable).toHaveBeenCalledWith('AWS_ACCESS_KEY_ID', 'prodAccessKeyId'); | ||
expect(core.exportVariable).toHaveBeenCalledWith('AWS_SECRET_ACCESS_KEY', 'prodSecretAccessKey'); | ||
}); | ||
|
||
it('should set AWS credentials for stage environment', () => { | ||
process.env['INPUT_ENVIRONMENT_NAME'] = 'stage'; | ||
|
||
setAwsCredentials(); | ||
|
||
expect(core.setSecret).toHaveBeenCalledWith('stageAccessKeyId'); | ||
expect(core.setSecret).toHaveBeenCalledWith('stageSecretAccessKey'); | ||
expect(core.exportVariable).toHaveBeenCalledWith('AWS_ACCESS_KEY_ID', 'stageAccessKeyId'); | ||
expect(core.exportVariable).toHaveBeenCalledWith('AWS_SECRET_ACCESS_KEY', 'stageSecretAccessKey'); | ||
}); | ||
|
||
it('should set core.setFailed when environment name is not supported', () => { | ||
process.env['INPUT_ENVIRONMENT_NAME'] = 'unsupported'; | ||
|
||
setAwsCredentials(); | ||
|
||
expect(core.setFailed).toHaveBeenCalledWith('Unsupported environment name: unsupported'); | ||
}); | ||
}); |
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,28 +1,28 @@ | ||
name: "Set AWS Credentials" | ||
description: "Sets AWS credentials based on the provided environment name." | ||
inputs: | ||
DEV_AWS_ACCESS_KEY_ID: | ||
description: "The AWS access key ID for the development environment." | ||
required: true | ||
DEV_AWS_SECRET_ACCESS_KEY: | ||
description: "The AWS secret access key for the development environment." | ||
required: true | ||
ENVIRONMENT_NAME: | ||
description: "The name of the environment to set the AWS credentials for." | ||
required: true | ||
PROD_AWS_ACCESS_KEY_ID: | ||
description: "The AWS access key ID for the production environment." | ||
required: true | ||
PROD_AWS_SECRET_ACCESS_KEY: | ||
description: "The AWS secret access key for the production environment." | ||
required: true | ||
STAGE_AWS_ACCESS_KEY_ID: | ||
description: "The AWS access key ID for the staging environment." | ||
required: true | ||
STAGE_AWS_SECRET_ACCESS_KEY: | ||
description: "The AWS secret access key for the staging environment." | ||
required: true | ||
|
||
runs: | ||
using: "node20" | ||
main: "set-aws-credentials.js" | ||
name: "Set AWS Credentials" | ||
description: "Sets AWS credentials based on the provided environment name." | ||
inputs: | ||
DEV_AWS_ACCESS_KEY_ID: | ||
description: "The AWS access key ID for the development environment." | ||
required: true | ||
DEV_AWS_SECRET_ACCESS_KEY: | ||
description: "The AWS secret access key for the development environment." | ||
required: true | ||
ENVIRONMENT_NAME: | ||
description: "The name of the environment to set the AWS credentials for." | ||
required: true | ||
PROD_AWS_ACCESS_KEY_ID: | ||
description: "The AWS access key ID for the production environment." | ||
required: true | ||
PROD_AWS_SECRET_ACCESS_KEY: | ||
description: "The AWS secret access key for the production environment." | ||
required: true | ||
STAGE_AWS_ACCESS_KEY_ID: | ||
description: "The AWS access key ID for the staging environment." | ||
required: true | ||
STAGE_AWS_SECRET_ACCESS_KEY: | ||
description: "The AWS secret access key for the staging environment." | ||
required: true | ||
|
||
runs: | ||
using: "node20" | ||
main: "set-aws-credentials.js" |
Oops, something went wrong.