Skip to content

Commit 2bdda9e

Browse files
Foresee logic to include test firm id in run-test action (#4)
* Foresee logic to include test firm id in run-test action * Check for exact matches in firm id + update node version * Adjust comment node version
1 parent 2145564 commit 2bdda9e

File tree

1 file changed

+62
-7
lines changed

1 file changed

+62
-7
lines changed

.github/workflows/run_tests.yml

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
changed_templates: ${{ steps.templates_changed.outputs.changed_templates }}
2222
steps:
2323
- name: Checkout Repository - Fetch all history for all tags and branches
24-
uses: actions/checkout@v3
24+
uses: actions/checkout@v4
2525
with:
2626
fetch-depth: 0
2727
- name: Get changed liquid files
@@ -70,18 +70,19 @@ jobs:
7070
env:
7171
SF_API_CLIENT_ID: "${{ secrets.SF_API_CLIENT_ID }}"
7272
SF_API_SECRET: "${{ secrets.SF_API_SECRET }}"
73+
SF_TEST_FIRM_ID: "${{ vars.SF_TEST_FIRM_ID }}"
7374
CHANGED_TEMPLATES: "${{ needs.check-changed-templates.outputs.changed_templates }}"
7475
if: ${{ needs.check-changed-templates.outputs.changed_templates != '[]' }}
7576
needs: [check-auth, check-changed-templates]
7677
steps:
7778
- name: Checkout Repository - Fetch all history for all tags and branches
78-
uses: actions/checkout@v3
79+
uses: actions/checkout@v4
7980
with:
8081
fetch-depth: 0
81-
- name: Setup Node v18
82-
uses: actions/setup-node@v3
82+
- name: Setup Node v20
83+
uses: actions/setup-node@v4
8384
with:
84-
node-version: 18
85+
node-version: 20
8586
- name: Load Silverfin config file from secrets
8687
run: |
8788
mkdir -p $HOME/.silverfin/
@@ -100,7 +101,61 @@ jobs:
100101
while [[ "${CURRENT_DIR}" != "." ]]; do
101102
if [[ -e "${CURRENT_DIR}/config.json" ]]; then
102103
HANDLE=$(cat ${CURRENT_DIR}/config.json | jq -r ".handle // .name")
103-
FIRM_ID=$(cat ${CURRENT_DIR}/config.json | jq -r ".id" | jq "keys_unsorted" | jq "first" | tr -d '"')
104+
105+
# Initialize FIRM_ID
106+
FIRM_ID=""
107+
108+
# Check if test_firm_id is present in config
109+
TEST_FIRM_ID=$(cat ${CURRENT_DIR}/config.json | jq -r ".test_firm_id // empty")
110+
111+
if [[ -n "$TEST_FIRM_ID" && "$TEST_FIRM_ID" != "null" ]]; then
112+
# 1. Template-specific test_firm_id (highest priority)
113+
AVAILABLE_FIRM_IDS=$(cat ${CURRENT_DIR}/config.json | jq -r ".id | keys[]" 2>/dev/null || echo "")
114+
115+
# Check for exact match by looping through available IDs
116+
FOUND_MATCH=false
117+
for available_id in $AVAILABLE_FIRM_IDS; do
118+
if [[ "$available_id" == "$TEST_FIRM_ID" ]]; then
119+
FOUND_MATCH=true
120+
break
121+
fi
122+
done
123+
124+
if [[ "$FOUND_MATCH" == "true" ]]; then
125+
FIRM_ID="$TEST_FIRM_ID"
126+
echo "Using configured test_firm_id: ${FIRM_ID}"
127+
else
128+
echo "Warning: test_firm_id '${TEST_FIRM_ID}' not found in .id object, falling back to environment variable or default"
129+
fi
130+
fi
131+
132+
if [[ -z "$FIRM_ID" && -n "$SF_TEST_FIRM_ID" ]]; then
133+
# 2. Environment variable fallback
134+
AVAILABLE_FIRM_IDS=$(cat ${CURRENT_DIR}/config.json | jq -r ".id | keys[]" 2>/dev/null || echo "")
135+
136+
# Check for exact match by looping through available IDs
137+
FOUND_MATCH=false
138+
for available_id in $AVAILABLE_FIRM_IDS; do
139+
if [[ "$available_id" == "$SF_TEST_FIRM_ID" ]]; then
140+
FOUND_MATCH=true
141+
break
142+
fi
143+
done
144+
145+
if [[ "$FOUND_MATCH" == "true" ]]; then
146+
FIRM_ID="$SF_TEST_FIRM_ID"
147+
echo "Using SF_TEST_FIRM_ID environment variable: ${FIRM_ID}"
148+
else
149+
echo "Warning: SF_TEST_FIRM_ID '${SF_TEST_FIRM_ID}' not found in .id object, falling back to default"
150+
fi
151+
fi
152+
153+
if [[ -z "$FIRM_ID" ]]; then
154+
# 3. Default behavior - use first available firm ID
155+
FIRM_ID=$(cat ${CURRENT_DIR}/config.json | jq -r ".id" | jq "keys_unsorted" | jq "first" | tr -d '"')
156+
echo "Using first available firm ID: ${FIRM_ID}"
157+
fi
158+
104159
if [[ "${CURRENT_DIR}" == *reconciliation_texts* ]]; then
105160
# FETCH THE NEWEST VERSION OF THE TOKENS FROM THE SECRETS, IN CASE THEY WERE UPDATED BY THE INITIATION OF A CONCURRENT WORKFLOW
106161
echo '${{ secrets.CONFIG_JSON }}' > $HOME/.silverfin/config.json
@@ -134,7 +189,7 @@ jobs:
134189
echo "Errors: ${ERRORS[@]}, please run the tests locally to fix the errors"
135190
exit 1
136191
fi
137-
192+
138193
# - name: Get changed files in the shared_parts folder
139194
# id: changed-files-shared-parts
140195
# uses: tj-actions/changed-files@v35

0 commit comments

Comments
 (0)