Skip to content

Commit

Permalink
Merge pull request #23 from im-open/transfer
Browse files Browse the repository at this point in the history
ARCH-1919 - Transfer to Infra-Purple
  • Loading branch information
danielle-casella-adams committed Oct 17, 2023
2 parents 134890f + 055de12 commit 5327bb7
Show file tree
Hide file tree
Showing 8 changed files with 235 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @im-open/swat
* @im-open/infra-purple
181 changes: 181 additions & 0 deletions .github/workflows/build-and-review-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,184 @@ jobs:
# The npm script to run to build the action. This is typically 'npm run build' if the
# action needs to be compiled. For composite-run-steps actions this is typically empty.
build-command: 'npm run build'

test:
runs-on: ubuntu-latest

env:
DB_NAME: ''
DB_SERVER: ''
TIMEOUT: ''
APP_NAME: ''
CUSTOM_ERROR: ''
LOG_LEVEL: ''
CACHE_EXP_IN_HOURS: ''
NO_MATCH_SETTING_1: ''
NO_MATCH_SETTING_2: ''
NO_MATCH_SETTING_3: ''
NO_MATCH_SETTING_4: ''

steps:
- uses: actions/checkout@v3

#---------------------------------------------------------
# MATCHING SCOPE WITH CREATE-OUTPUT-VARIABLES SET TO FALSE
#---------------------------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""

- name: When there are matching scopes and create-output-variables is false
uses: ./
if: always()
id: matching-scope-no-outputs
with:
scope: 'dev'
create-output-variables: false
env:
DB_NAME@dev: 'db-dev'
DB_NAME@prod: 'db-prod'
DB_SERVER@dev: 'server-dev'
DB_SERVER@prod: 'server-prod'
TIMEOUT@dev prod: '32'

- name: Then the outcome should be success
if: always()
run: |
./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.matching-scope-no-outputs.outcome }}"
- name: And the environment variables should be populated
if: always()
run: |
./test/assert-values-match.sh --name "DB_NAME" --expected "db-dev" --actual "${{ env.DB_NAME }}"
./test/assert-values-match.sh --name "DB_SERVER" --expected "server-dev" --actual "${{ env.DB_SERVER }}"
./test/assert-values-match.sh --name "TIMEOUT" --expected "32" --actual "${{ env.TIMEOUT }}"
- name: And the outputs should not be populated
if: always()
run: |
./test/assert-values-match.sh --name "DB_NAME output" --expected "" --actual "${{ steps.matching-scope-no-outputs.outputs.DB_NAME }}"
./test/assert-values-match.sh --name "DB_SERVER output" --expected "" --actual "${{ steps.matching-scope-no-outputs.outputs.DB_SERVER }}"
./test/assert-values-match.sh --name "TIMEOUT output" --expected "" --actual "${{ steps.matching-scope-no-outputs.outputs.TIMEOUT }}"
#--------------------------------------------------------
# MATCHING SCOPE WITH CREATE-OUTPUT-VARIABLES SET TO TRUE
#--------------------------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""

- name: When there are matching scopes and create-output-variables is true
uses: ./
if: always()
id: matching-scope-with-outputs
with:
scope: 'Dev' # This should not be case sensitive
create-output-variables: true
env:
APP_NAME@dev: 'db-dev'
APP_NAME@prod: 'db-prod'
CUSTOM_ERROR@dev prod: 'custom'

- name: Then the outcome should be success
if: always()
run: |
./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.matching-scope-with-outputs.outcome }}"
- name: And the environment variables and outputs should match
if: always()
run: |
./test/assert-values-match.sh --name "APP_NAME" --expected "${{ env.APP_NAME }}" --actual "${{ steps.matching-scope-with-outputs.outputs.APP_NAME }}"
./test/assert-values-match.sh --name "CUSTOM_ERROR" --expected "${{ env.CUSTOM_ERROR }}" --actual "${{ steps.matching-scope-with-outputs.outputs.CUSTOM_ERROR }}"
#--------------------------------------------
# MATCHING SCOPE WHEN PROVIDING AN INPUT FILE
#--------------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""

- name: When there is a matching scope and an input file
uses: ./
if: always()
id: input-file
with:
scope: 'dev'
create-output-variables: true
input-file: ./test/config.yml

- name: Then the outcome should be success
if: always()
run: |
./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.input-file.outcome }}"
- name: And the environment variables and outputs should match
if: always()
run: |
./test/assert-values-match.sh --name "LOG_LEVEL" --expected "${{ env.LOG_LEVEL }}" --actual "${{ steps.input-file.outputs.LOG_LEVEL }}"
./test/assert-values-match.sh --name "CACHE_EXP_IN_HOURS" --expected "${{ env.CACHE_EXP_IN_HOURS }}" --actual "${{ steps.input-file.outputs.CACHE_EXP_IN_HOURS }}"
#--------------------------------------------------------
# NO MATCHING SCOPE WITH ERROR-ON-NO-MATCH SET TO FALSE
#--------------------------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""

- name: When there are no matching scopes and error-on-no-match is false
uses: ./
if: always()
id: no-matching-scope-no-error
with:
scope: 'aScopeThatDoesNotMatchAnything'
create-output-variables: true
error-on-no-match: false
env:
SETTING_1@dev: 's1-d'
SETTING_1@prod: 's1-p'
SETTING_2@dev prod: 'setting2'

- name: Then the outcome should be success
if: always()
run: |
./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.no-matching-scope-no-error.outcome }}"
- name: And no environment variables or outputs should be created
if: always()
run: |
./test/assert-values-match.sh --name "step outcome" --expected "" --actual "${{ env.NO_MATCH_SETTING_1 }}"
./test/assert-values-match.sh --name "step outcome" --expected "" --actual "${{ env.NO_MATCH_SETTING_2 }}"
./test/assert-values-match.sh --name "step outcome" --expected "" --actual "${{ steps.no-matching-scope-no-error.outputs.NO_MATCH_SETTING_1 }}"
./test/assert-values-match.sh --name "step outcome" --expected "" --actual "${{ steps.no-matching-scope-no-error.outputs.NO_MATCH_SETTING_2 }}"
#--------------------------------------------------------
# NO MATCHING SCOPE WITH ERROR-ON-NO-MATCH SET TO TRUE
#--------------------------------------------------------
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""

- name: When there are no matching scopes and error-on-no-match is true
uses: ./
if: always()
continue-on-error: true # This is needed because we expect the step to fail. It needs to "pass" in order for the test job to succeed.
id: no-matching-scope-with-error
with:
scope: 'aScopeThatDoesNotMatchAnything_part2'
create-output-variables: true
error-on-no-match: true
env:
SETTING_3@dev: 's3-d'
SETTING_3@prod: 's3-p'
SETTING_4@dev prod: 'setting4'

- name: Then the outcome should be failure
if: always()
run: |
./test/assert-values-match.sh --name "step outcome" --expected "failure" --actual "${{ steps.no-matching-scope-with-error.outcome }}"
- name: And no environment variables or outputs should be created
if: always()
run: |
./test/assert-values-match.sh --name "step outcome" --expected "" --actual "${{ env.NO_MATCH_SETTING_3 }}"
./test/assert-values-match.sh --name "step outcome" --expected "" --actual "${{ env.NO_MATCH_SETTING_4 }}"
./test/assert-values-match.sh --name "step outcome" --expected "" --actual "${{ steps.no-matching-scope-with-error.outputs.NO_MATCH_SETTING_3 }}"
./test/assert-values-match.sh --name "step outcome" --expected "" --actual "${{ steps.no-matching-scope-with-error.outputs.NO_MATCH_SETTING_4 }}"
- name: '-------------------------------------------------------------------------------------------------------'
run: echo ""
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This action sets environment variables, (and optionally step outputs), to differ
- [Source Code Changes](#source-code-changes)
- [Recompiling Manually](#recompiling-manually)
- [Updating the README.md](#updating-the-readmemd)
- [Tests](#tests)
- [Code of Conduct](#code-of-conduct)
- [License](#license)

Expand All @@ -29,7 +30,7 @@ This action sets environment variables, (and optionally step outputs), to differ
|---------------------------|-------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `scope` | true | The scope is used to identify which value to select for each key name. See the usage instructions below. |
| `input-file` | false | A specially formatted YAML file containing possible environment variable candidates with their associated scopes. |
| `create-output-variables` | false | Create output variables (in addiction to environment variables) for use in other steps and jobs. Accepts true or false. Defaults to false. |
| `create-output-variables` | false | Create output variables (in addition to environment variables) for use in other steps and jobs. Accepts true or false. Defaults to false. |
| `error-on-no-match` | false | An error will be thrown if no environment variables or outputs are created, a warning will appear for all keys that don't provide a value for the input scope. |
| `custom-error-message` | false | The error message that will be displayed if no environment or output variables are created. `error_on_no_match` must be set to true |

Expand Down Expand Up @@ -65,7 +66,7 @@ jobs:
steps:
- name: Set environment
id: env-scope
uses: im-open/set-environment-variables-by-scope@v1.1.4
uses: im-open/set-environment-variables-by-scope@v1.1.5
with:
scope: ${{ workflow.inputs.environment }}
create-output-variables: true
Expand All @@ -90,7 +91,7 @@ jobs:
# the supplied env variables to create the resulting environment and output vars
- name: Build Workflow Environment Variables
# You may also reference just the major or major.minor version
uses: im-open/set-environment-variables-by-scope@v1.1.4
uses: im-open/set-environment-variables-by-scope@v1.1.5
with:
scope: ${{ needs.setup.outputs.env-scope }}
input-file: ./env-vars.yml
Expand Down Expand Up @@ -157,7 +158,7 @@ GitHub actions expressions can be used in the _`key-value`_ when supplying input

```yaml
- name: Build DB Connection
uses: im-open/set-environment-variables-by-scope@v1.1.4
uses: im-open/set-environment-variables-by-scope@v1.1.5
with:
scope: ${{ needs.setup.outputs.env-scope }}
env:
Expand Down Expand Up @@ -201,6 +202,7 @@ When creating PRs, please review the following guidelines:
- [ ] At least one of the commit messages contains the appropriate `+semver:` keywords listed under [Incrementing the Version] for major and minor increments.
- [ ] The action has been recompiled. See [Recompiling Manually] for details.
- [ ] The README.md has been updated with the latest version of the action. See [Updating the README.md] for details.
- [ ] Any tests in the [build-and-review-pr] workflow are passing

### Incrementing the Version

Expand Down Expand Up @@ -235,6 +237,10 @@ npm run build

If changes are made to the action's [source code], the [usage examples] section of this file should be updated with the next version of the action. Each instance of this action should be updated. This helps users know what the latest tag is without having to navigate to the Tags page of the repository. See [Incrementing the Version] for details on how to determine what the next version will be or consult the first workflow run for the PR which will also calculate the next version.

### Tests

The build and review PR workflow includes tests which are linked to a status check. That status check needs to succeed before a PR is merged to the default branch. The tests do not need special permissions, so they should succeed whether they come from a branch or a fork.

## Code of Conduct

This project has adopted the [im-open's Code of Conduct](https://github.com/im-open/.github/blob/main/CODE_OF_CONDUCT.md).
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ inputs:
description: 'A specially formatted YAML file containing possible environment variable candidates with their associated scopes'
required: false
create-output-variables:
description: 'Create output variables (in addiction to environment variables) for use in other steps and jobs, accepts true or false, defaults to false'
description: 'Create output variables (in addition to environment variables) for use in other steps and jobs, accepts true or false, defaults to false'
required: false
default: 'false'
error-on-no-match:
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8806,7 +8806,7 @@ var require_action_library = __commonJS({
}
for (let e in environmentScoped) {
if (scopedItems[e]) {
core2.warning(`<<${e}>>: key and scope specified as env and input file var, env var will be used.`);
core2.warning(`<<${e}>>: was specified by both environment variable and input file. Environment variable will be used.`);
}
scopedItems[e] = environmentScoped[e];
}
Expand Down
2 changes: 1 addition & 1 deletion src/action_library.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class action_library {
}
for (let e in environmentScoped) {
if (scopedItems[e]) {
core.warning(`<<${e}>>: key and scope specified as env and input file var, env var will be used.`);
core.warning(`<<${e}>>: was specified by both environment variable and input file. Environment variable will be used.`);
}
scopedItems[e] = environmentScoped[e];
}
Expand Down
37 changes: 37 additions & 0 deletions test/assert-values-match.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

name=''
expectedValue=''
actualValue=''

for arg in "$@"; do
case $arg in
--name)
name=$2
shift # Remove argument --name from `$@`
shift # Remove argument value from `$@`
;;
--expected)
expectedValue=$2
shift # Remove argument --expected from `$@`
shift # Remove argument value from `$@`
;;
--actual)
actualValue=$2
shift # Remove argument --actual from `$@`
shift # Remove argument value from `$@`
;;

esac
done

echo "
Expected $name: '$expectedValue'"
echo "Actual $name: '$actualValue'"

if [ "$expectedValue" != "$actualValue" ]; then
echo "The expected $name does not match the actual $name."
exit 1
else
echo "The expected and actual $name values match."
fi
3 changes: 3 additions & 0 deletions test/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
LOG_LEVEL@dev: 'debug'
LOG_LEVEL@prod: 'info'
CACHE_EXP_IN_HOURS@dev prod: '1'

0 comments on commit 5327bb7

Please sign in to comment.