Skip to content

Commit d726e14

Browse files
Add GitHub token for private rspec repository access in update-rule-metadata
The rspec repository is now private, requiring authentication. This adds a GitHub token from vault and passes it as GITHUB_TOKEN env variable to the rule-api execution step. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2c9fb82 commit d726e14

File tree

3 files changed

+66
-7
lines changed

3 files changed

+66
-7
lines changed

.github/workflows/test-update-rule-metadata.yml

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,56 @@ jobs:
165165
echo "✓ All expected outputs are defined"
166166
echo "✓ Output schema validation complete"
167167
168+
vault-and-env-tests:
169+
name: Test Vault Secrets and Environment Variables
170+
runs-on: ubuntu-latest
171+
172+
steps:
173+
- name: Checkout code
174+
uses: actions/checkout@v4
175+
176+
- name: Verify GitHub token vault secret is configured
177+
run: |
178+
echo "Testing that vault secrets include GitHub token..."
179+
180+
# Test that the vault step retrieves a GitHub token for private rspec repo access
181+
if grep -A10 "Get vault secrets" update-rule-metadata/action.yml | grep -q "development/github/token/{REPO_OWNER_NAME_DASH}-its"; then
182+
echo "✓ GitHub token vault secret path found"
183+
else
184+
echo "✗ GitHub token vault secret path not found in vault step"
185+
exit 1
186+
fi
187+
188+
# Test that the GitHub token is mapped to GITHUB_TOKEN
189+
if grep -A10 "Get vault secrets" update-rule-metadata/action.yml | grep -q "GITHUB_TOKEN"; then
190+
echo "✓ GITHUB_TOKEN mapping found in vault secrets"
191+
else
192+
echo "✗ GITHUB_TOKEN mapping not found in vault secrets"
193+
exit 1
194+
fi
195+
196+
- name: Verify GITHUB_TOKEN is passed to rule-api execution step
197+
run: |
198+
echo "Testing that rule-api step has GITHUB_TOKEN in env..."
199+
200+
# Extract the rule-api step block (from "Run rule-api" to the next step marker)
201+
STEP_BLOCK=$(sed -n '/name: Run rule-api to update metadata/,/^ - name: Remove rule-api/p' update-rule-metadata/action.yml)
202+
203+
if echo "$STEP_BLOCK" | grep -q "GITHUB_TOKEN"; then
204+
echo "✓ GITHUB_TOKEN found in rule-api execution step"
205+
else
206+
echo "✗ GITHUB_TOKEN not found in rule-api execution step"
207+
exit 1
208+
fi
209+
210+
# Verify it references the vault output
211+
if echo "$STEP_BLOCK" | grep -q "fromJSON(steps.secrets.outputs.vault).GITHUB_TOKEN"; then
212+
echo "✓ GITHUB_TOKEN references vault output correctly"
213+
else
214+
echo "✗ GITHUB_TOKEN does not reference vault output"
215+
exit 1
216+
fi
217+
168218
integration-tests:
169219
name: Integration Tests
170220
runs-on: ubuntu-latest
@@ -212,7 +262,7 @@ jobs:
212262
validation-summary:
213263
name: Test Summary
214264
runs-on: ubuntu-latest
215-
needs: [input-parameter-tests, branch-parameter-tests, output-validation, integration-tests]
265+
needs: [input-parameter-tests, branch-parameter-tests, output-validation, integration-tests, vault-and-env-tests]
216266
if: always()
217267

218268
steps:
@@ -225,11 +275,13 @@ jobs:
225275
echo "Branch Parameter Tests: ${{ needs.branch-parameter-tests.result }}"
226276
echo "Output Validation: ${{ needs.output-validation.result }}"
227277
echo "Integration Tests: ${{ needs.integration-tests.result }}"
278+
echo "Vault & Env Variable Tests: ${{ needs.vault-and-env-tests.result }}"
228279
echo "================================"
229280
230281
if [[ "${{ needs.input-parameter-tests.result }}" == "success" && \
231282
"${{ needs.branch-parameter-tests.result }}" == "success" && \
232-
"${{ needs.output-validation.result }}" == "success" ]]; then
283+
"${{ needs.output-validation.result }}" == "success" && \
284+
"${{ needs.vault-and-env-tests.result }}" == "success" ]]; then
233285
echo "✓ All validation tests passed!"
234286
echo "✓ Action is properly configured and ready to use"
235287
else

update-rule-metadata/README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ The action performs the following operations:
1414
## Dependencies
1515

1616
This action depends on:
17-
- [SonarSource/vault-action-wrapper](https://github.com/SonarSource/vault-action-wrapper) for retrieving Artifactory credentials
17+
- [SonarSource/vault-action-wrapper](https://github.com/SonarSource/vault-action-wrapper) for retrieving Artifactory credentials and GitHub token
1818
- Java 17 runtime for executing the rule-api JAR
1919
- Git for detecting changes and creating pull requests
2020
- [peter-evans/create-pull-request](https://github.com/peter-evans/create-pull-request) for automated PR creation
@@ -105,6 +105,7 @@ jobs:
105105
106106
The action uses a bash script that:
107107
- Authenticates with Artifactory using credentials from HashiCorp Vault
108+
- Retrieves a GitHub token from Vault for accessing the private rspec repository
108109
- Downloads and caches the specified rule-api JAR version
109110
- Automatically discovers all directories containing sonarpedia.json files (unless specific files are provided)
110111
- Changes into each directory and runs the rule-api update command
@@ -113,8 +114,11 @@ The action uses a bash script that:
113114
114115
## Prerequisites
115116
116-
The action requires that the repository has the `development/artifactory/token/{REPO_OWNER_NAME_DASH}-private-reader` token configured in vault.
117-
This can be done using the SPEED self-service portal ([more info](https://xtranet-sonarsource.atlassian.net/wiki/spaces/Platform/pages/3553787989/Manage+Vault+Policy+-+SPEED)).
117+
The action requires the following tokens configured in vault:
118+
- `development/artifactory/token/{REPO_OWNER_NAME_DASH}-private-reader` for downloading the rule-api JAR from Artifactory
119+
- `development/github/token/{REPO_OWNER_NAME_DASH}-its` for authenticating with the private rspec repository
120+
121+
These can be configured using the SPEED self-service portal ([more info](https://xtranet-sonarsource.atlassian.net/wiki/spaces/Platform/pages/3553787989/Manage+Vault+Policy+-+SPEED)).
118122

119123
The repository must have:
120124
- Proper sonarpedia.json files in language-specific directories
@@ -123,7 +127,7 @@ The repository must have:
123127

124128
## Notes
125129

126-
- This action requires access to SonarSource's HashiCorp Vault for Artifactory credentials
130+
- This action requires access to SonarSource's HashiCorp Vault for Artifactory credentials and a GitHub token for the private rspec repository
127131
- The action automatically discovers all sonarpedia.json files unless specific files are provided
128132
- Pull requests are created with the label `skip-qa` and target the specified branch (defaults to `master`)
129133
- The rule-api JAR is cached to improve performance on subsequent runs

update-rule-metadata/action.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ runs:
4343
with:
4444
secrets: |
4545
development/artifactory/token/{REPO_OWNER_NAME_DASH}-private-reader access_token | ARTIFACTORY_ACCESS_TOKEN;
46-
development/artifactory/token/{REPO_OWNER_NAME_DASH}-private-reader role | ARTIFACTORY_ROLE;
46+
development/artifactory/token/{REPO_OWNER_NAME_DASH}-private-reader role | ARTIFACTORY_ROLE;
47+
development/github/token/{REPO_OWNER_NAME_DASH}-its token | GITHUB_TOKEN;
4748
4849
- name: Cache rule-api jar
4950
id: cache-rule-api
@@ -72,6 +73,8 @@ runs:
7273

7374
- name: Run rule-api to update metadata
7475
shell: bash
76+
env:
77+
GITHUB_TOKEN: ${{ fromJSON(steps.secrets.outputs.vault).GITHUB_TOKEN }}
7578
run: |
7679
echo "" > rule-api-logs.txt
7780

0 commit comments

Comments
 (0)