Skip to content

Commit 5327bb7

Browse files
Merge pull request #23 from im-open/transfer
ARCH-1919 - Transfer to Infra-Purple
2 parents 134890f + 055de12 commit 5327bb7

File tree

8 files changed

+235
-8
lines changed

8 files changed

+235
-8
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @im-open/swat
1+
* @im-open/infra-purple

.github/workflows/build-and-review-pr.yml

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,184 @@ jobs:
6060
# The npm script to run to build the action. This is typically 'npm run build' if the
6161
# action needs to be compiled. For composite-run-steps actions this is typically empty.
6262
build-command: 'npm run build'
63+
64+
test:
65+
runs-on: ubuntu-latest
66+
67+
env:
68+
DB_NAME: ''
69+
DB_SERVER: ''
70+
TIMEOUT: ''
71+
APP_NAME: ''
72+
CUSTOM_ERROR: ''
73+
LOG_LEVEL: ''
74+
CACHE_EXP_IN_HOURS: ''
75+
NO_MATCH_SETTING_1: ''
76+
NO_MATCH_SETTING_2: ''
77+
NO_MATCH_SETTING_3: ''
78+
NO_MATCH_SETTING_4: ''
79+
80+
steps:
81+
- uses: actions/checkout@v3
82+
83+
#---------------------------------------------------------
84+
# MATCHING SCOPE WITH CREATE-OUTPUT-VARIABLES SET TO FALSE
85+
#---------------------------------------------------------
86+
- name: '-------------------------------------------------------------------------------------------------------'
87+
run: echo ""
88+
89+
- name: When there are matching scopes and create-output-variables is false
90+
uses: ./
91+
if: always()
92+
id: matching-scope-no-outputs
93+
with:
94+
scope: 'dev'
95+
create-output-variables: false
96+
env:
97+
DB_NAME@dev: 'db-dev'
98+
DB_NAME@prod: 'db-prod'
99+
DB_SERVER@dev: 'server-dev'
100+
DB_SERVER@prod: 'server-prod'
101+
TIMEOUT@dev prod: '32'
102+
103+
- name: Then the outcome should be success
104+
if: always()
105+
run: |
106+
./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.matching-scope-no-outputs.outcome }}"
107+
108+
- name: And the environment variables should be populated
109+
if: always()
110+
run: |
111+
./test/assert-values-match.sh --name "DB_NAME" --expected "db-dev" --actual "${{ env.DB_NAME }}"
112+
./test/assert-values-match.sh --name "DB_SERVER" --expected "server-dev" --actual "${{ env.DB_SERVER }}"
113+
./test/assert-values-match.sh --name "TIMEOUT" --expected "32" --actual "${{ env.TIMEOUT }}"
114+
115+
- name: And the outputs should not be populated
116+
if: always()
117+
run: |
118+
./test/assert-values-match.sh --name "DB_NAME output" --expected "" --actual "${{ steps.matching-scope-no-outputs.outputs.DB_NAME }}"
119+
./test/assert-values-match.sh --name "DB_SERVER output" --expected "" --actual "${{ steps.matching-scope-no-outputs.outputs.DB_SERVER }}"
120+
./test/assert-values-match.sh --name "TIMEOUT output" --expected "" --actual "${{ steps.matching-scope-no-outputs.outputs.TIMEOUT }}"
121+
122+
#--------------------------------------------------------
123+
# MATCHING SCOPE WITH CREATE-OUTPUT-VARIABLES SET TO TRUE
124+
#--------------------------------------------------------
125+
- name: '-------------------------------------------------------------------------------------------------------'
126+
run: echo ""
127+
128+
- name: When there are matching scopes and create-output-variables is true
129+
uses: ./
130+
if: always()
131+
id: matching-scope-with-outputs
132+
with:
133+
scope: 'Dev' # This should not be case sensitive
134+
create-output-variables: true
135+
env:
136+
APP_NAME@dev: 'db-dev'
137+
APP_NAME@prod: 'db-prod'
138+
CUSTOM_ERROR@dev prod: 'custom'
139+
140+
- name: Then the outcome should be success
141+
if: always()
142+
run: |
143+
./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.matching-scope-with-outputs.outcome }}"
144+
145+
- name: And the environment variables and outputs should match
146+
if: always()
147+
run: |
148+
./test/assert-values-match.sh --name "APP_NAME" --expected "${{ env.APP_NAME }}" --actual "${{ steps.matching-scope-with-outputs.outputs.APP_NAME }}"
149+
./test/assert-values-match.sh --name "CUSTOM_ERROR" --expected "${{ env.CUSTOM_ERROR }}" --actual "${{ steps.matching-scope-with-outputs.outputs.CUSTOM_ERROR }}"
150+
151+
#--------------------------------------------
152+
# MATCHING SCOPE WHEN PROVIDING AN INPUT FILE
153+
#--------------------------------------------
154+
- name: '-------------------------------------------------------------------------------------------------------'
155+
run: echo ""
156+
157+
- name: When there is a matching scope and an input file
158+
uses: ./
159+
if: always()
160+
id: input-file
161+
with:
162+
scope: 'dev'
163+
create-output-variables: true
164+
input-file: ./test/config.yml
165+
166+
- name: Then the outcome should be success
167+
if: always()
168+
run: |
169+
./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.input-file.outcome }}"
170+
171+
- name: And the environment variables and outputs should match
172+
if: always()
173+
run: |
174+
./test/assert-values-match.sh --name "LOG_LEVEL" --expected "${{ env.LOG_LEVEL }}" --actual "${{ steps.input-file.outputs.LOG_LEVEL }}"
175+
./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 }}"
176+
177+
#--------------------------------------------------------
178+
# NO MATCHING SCOPE WITH ERROR-ON-NO-MATCH SET TO FALSE
179+
#--------------------------------------------------------
180+
- name: '-------------------------------------------------------------------------------------------------------'
181+
run: echo ""
182+
183+
- name: When there are no matching scopes and error-on-no-match is false
184+
uses: ./
185+
if: always()
186+
id: no-matching-scope-no-error
187+
with:
188+
scope: 'aScopeThatDoesNotMatchAnything'
189+
create-output-variables: true
190+
error-on-no-match: false
191+
env:
192+
SETTING_1@dev: 's1-d'
193+
SETTING_1@prod: 's1-p'
194+
SETTING_2@dev prod: 'setting2'
195+
196+
- name: Then the outcome should be success
197+
if: always()
198+
run: |
199+
./test/assert-values-match.sh --name "step outcome" --expected "success" --actual "${{ steps.no-matching-scope-no-error.outcome }}"
200+
201+
- name: And no environment variables or outputs should be created
202+
if: always()
203+
run: |
204+
./test/assert-values-match.sh --name "step outcome" --expected "" --actual "${{ env.NO_MATCH_SETTING_1 }}"
205+
./test/assert-values-match.sh --name "step outcome" --expected "" --actual "${{ env.NO_MATCH_SETTING_2 }}"
206+
./test/assert-values-match.sh --name "step outcome" --expected "" --actual "${{ steps.no-matching-scope-no-error.outputs.NO_MATCH_SETTING_1 }}"
207+
./test/assert-values-match.sh --name "step outcome" --expected "" --actual "${{ steps.no-matching-scope-no-error.outputs.NO_MATCH_SETTING_2 }}"
208+
209+
#--------------------------------------------------------
210+
# NO MATCHING SCOPE WITH ERROR-ON-NO-MATCH SET TO TRUE
211+
#--------------------------------------------------------
212+
- name: '-------------------------------------------------------------------------------------------------------'
213+
run: echo ""
214+
215+
- name: When there are no matching scopes and error-on-no-match is true
216+
uses: ./
217+
if: always()
218+
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.
219+
id: no-matching-scope-with-error
220+
with:
221+
scope: 'aScopeThatDoesNotMatchAnything_part2'
222+
create-output-variables: true
223+
error-on-no-match: true
224+
env:
225+
SETTING_3@dev: 's3-d'
226+
SETTING_3@prod: 's3-p'
227+
SETTING_4@dev prod: 'setting4'
228+
229+
- name: Then the outcome should be failure
230+
if: always()
231+
run: |
232+
./test/assert-values-match.sh --name "step outcome" --expected "failure" --actual "${{ steps.no-matching-scope-with-error.outcome }}"
233+
234+
- name: And no environment variables or outputs should be created
235+
if: always()
236+
run: |
237+
./test/assert-values-match.sh --name "step outcome" --expected "" --actual "${{ env.NO_MATCH_SETTING_3 }}"
238+
./test/assert-values-match.sh --name "step outcome" --expected "" --actual "${{ env.NO_MATCH_SETTING_4 }}"
239+
./test/assert-values-match.sh --name "step outcome" --expected "" --actual "${{ steps.no-matching-scope-with-error.outputs.NO_MATCH_SETTING_3 }}"
240+
./test/assert-values-match.sh --name "step outcome" --expected "" --actual "${{ steps.no-matching-scope-with-error.outputs.NO_MATCH_SETTING_4 }}"
241+
242+
- name: '-------------------------------------------------------------------------------------------------------'
243+
run: echo ""

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ This action sets environment variables, (and optionally step outputs), to differ
2020
- [Source Code Changes](#source-code-changes)
2121
- [Recompiling Manually](#recompiling-manually)
2222
- [Updating the README.md](#updating-the-readmemd)
23+
- [Tests](#tests)
2324
- [Code of Conduct](#code-of-conduct)
2425
- [License](#license)
2526

@@ -29,7 +30,7 @@ This action sets environment variables, (and optionally step outputs), to differ
2930
|---------------------------|-------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
3031
| `scope` | true | The scope is used to identify which value to select for each key name. See the usage instructions below. |
3132
| `input-file` | false | A specially formatted YAML file containing possible environment variable candidates with their associated scopes. |
32-
| `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. |
33+
| `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. |
3334
| `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. |
3435
| `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 |
3536

@@ -65,7 +66,7 @@ jobs:
6566
steps:
6667
- name: Set environment
6768
id: env-scope
68-
uses: im-open/set-environment-variables-by-scope@v1.1.4
69+
uses: im-open/set-environment-variables-by-scope@v1.1.5
6970
with:
7071
scope: ${{ workflow.inputs.environment }}
7172
create-output-variables: true
@@ -90,7 +91,7 @@ jobs:
9091
# the supplied env variables to create the resulting environment and output vars
9192
- name: Build Workflow Environment Variables
9293
# You may also reference just the major or major.minor version
93-
uses: im-open/set-environment-variables-by-scope@v1.1.4
94+
uses: im-open/set-environment-variables-by-scope@v1.1.5
9495
with:
9596
scope: ${{ needs.setup.outputs.env-scope }}
9697
input-file: ./env-vars.yml
@@ -157,7 +158,7 @@ GitHub actions expressions can be used in the _`key-value`_ when supplying input
157158

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

205207
### Incrementing the Version
206208

@@ -235,6 +237,10 @@ npm run build
235237

236238
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.
237239

240+
### Tests
241+
242+
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.
243+
238244
## Code of Conduct
239245

240246
This project has adopted the [im-open's Code of Conduct](https://github.com/im-open/.github/blob/main/CODE_OF_CONDUCT.md).

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ inputs:
99
description: 'A specially formatted YAML file containing possible environment variable candidates with their associated scopes'
1010
required: false
1111
create-output-variables:
12-
description: 'Create output variables (in addiction to environment variables) for use in other steps and jobs, accepts true or false, defaults to false'
12+
description: 'Create output variables (in addition to environment variables) for use in other steps and jobs, accepts true or false, defaults to false'
1313
required: false
1414
default: 'false'
1515
error-on-no-match:

dist/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8806,7 +8806,7 @@ var require_action_library = __commonJS({
88068806
}
88078807
for (let e in environmentScoped) {
88088808
if (scopedItems[e]) {
8809-
core2.warning(`<<${e}>>: key and scope specified as env and input file var, env var will be used.`);
8809+
core2.warning(`<<${e}>>: was specified by both environment variable and input file. Environment variable will be used.`);
88108810
}
88118811
scopedItems[e] = environmentScoped[e];
88128812
}

src/action_library.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class action_library {
6565
}
6666
for (let e in environmentScoped) {
6767
if (scopedItems[e]) {
68-
core.warning(`<<${e}>>: key and scope specified as env and input file var, env var will be used.`);
68+
core.warning(`<<${e}>>: was specified by both environment variable and input file. Environment variable will be used.`);
6969
}
7070
scopedItems[e] = environmentScoped[e];
7171
}

test/assert-values-match.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
3+
name=''
4+
expectedValue=''
5+
actualValue=''
6+
7+
for arg in "$@"; do
8+
case $arg in
9+
--name)
10+
name=$2
11+
shift # Remove argument --name from `$@`
12+
shift # Remove argument value from `$@`
13+
;;
14+
--expected)
15+
expectedValue=$2
16+
shift # Remove argument --expected from `$@`
17+
shift # Remove argument value from `$@`
18+
;;
19+
--actual)
20+
actualValue=$2
21+
shift # Remove argument --actual from `$@`
22+
shift # Remove argument value from `$@`
23+
;;
24+
25+
esac
26+
done
27+
28+
echo "
29+
Expected $name: '$expectedValue'"
30+
echo "Actual $name: '$actualValue'"
31+
32+
if [ "$expectedValue" != "$actualValue" ]; then
33+
echo "The expected $name does not match the actual $name."
34+
exit 1
35+
else
36+
echo "The expected and actual $name values match."
37+
fi

test/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
LOG_LEVEL@dev: 'debug'
2+
LOG_LEVEL@prod: 'info'
3+
CACHE_EXP_IN_HOURS@dev prod: '1'

0 commit comments

Comments
 (0)