Skip to content

Commit b0b1674

Browse files
SONARXML-322 Use shared update rule metadata worflow (#426)
1 parent ae77e61 commit b0b1674

File tree

1 file changed

+20
-62
lines changed

1 file changed

+20
-62
lines changed

.github/workflows/UpdateRuleMetadata.yml

Lines changed: 20 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,30 @@ name: Update Rule Metadata
22

33
on: workflow_dispatch
44

5-
env:
6-
PR_BRANCH_NAME: "gh-action/update-rule-metadata.${{ github.run_id }}"
7-
85
jobs:
9-
UpdateRuleMetadata_job:
10-
name: Update Rule Metadata
6+
update-rule-metadata:
117
runs-on: github-ubuntu-latest-s
128
permissions:
13-
pull-requests: write
14-
contents: write
159
id-token: write
16-
10+
contents: write
11+
pull-requests: write
1712
steps:
18-
19-
- name: Checkout Sources
20-
uses: actions/checkout@v4
21-
22-
- name: Setup JFrog
23-
uses: SonarSource/jfrog-setup-wrapper@v3
13+
- name: Update Rule Metadata
14+
id: update-rule-metadata
15+
uses: SonarSource/release-github-actions/update-rule-metadata@v1
2416
with:
25-
artifactoryRoleSuffix: private-reader
26-
27-
- name: Setup Rule API
28-
run: |
29-
jfrog rt curl -sLf "sonarsource-private-releases/com/sonarsource/rule-api/rule-api/%5BRELEASE%5D/rule-api-%5BRELEASE%5D.jar" -o rule-api.jar
30-
echo "Latest com.sonarsource.rule-api:rule-api release:"
31-
jar xf rule-api.jar META-INF/MANIFEST.MF
32-
grep 'Implementation-Version' META-INF/MANIFEST.MF
33-
working-directory: /tmp
34-
35-
- name: Setup Java
36-
uses: actions/setup-java@v4
37-
with:
38-
distribution: 'temurin'
39-
java-version: '21'
40-
41-
- name: Getting Vault Secrets
42-
id: secrets
43-
uses: SonarSource/vault-action-wrapper@545e7cfbb5528e7009a1edcc83e073898d292627 # 3.2.0
44-
with:
45-
secrets: |
46-
development/github/token/{REPO_OWNER_NAME_DASH}-rspec token | GITHUB_TOKEN_RSPEC;
47-
48-
- name: Update Files
49-
env:
50-
GITHUB_TOKEN: ${{ fromJSON(steps.secrets.outputs.vault).GITHUB_TOKEN_RSPEC }}
51-
run: |
52-
java -jar "/tmp/rule-api.jar" update
53-
java -jar "/tmp/rule-api.jar" generate -rule XPathCheck
54-
cp sonar-xml-plugin/src/main/resources/org/sonar/l10n/xml/rules/xml/S140.html sonar-xml-plugin/src/main/resources/org/sonar/l10n/xml/rules/xml/XPathCheck.html
55-
cp sonar-xml-plugin/src/main/resources/org/sonar/l10n/xml/rules/xml/S140.json sonar-xml-plugin/src/main/resources/org/sonar/l10n/xml/rules/xml/XPathCheck.json
56-
57-
- name: Create PR
58-
id: create-pr
59-
env:
60-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61-
run: |
62-
git config user.name "${GITHUB_ACTOR}"
63-
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
64-
git checkout -b "${{ env.PR_BRANCH_NAME }}"
65-
git commit -m 'Update rule metadata' -a
66-
git push --set-upstream origin "${{ env.PR_BRANCH_NAME }}"
67-
URL=$(gh pr create -B master --title 'Update rule metadata' --body '')
68-
echo "url=${URL}" >> $GITHUB_OUTPUT
69-
70-
- name: Summary
17+
labels: ''
18+
# The default suffix is `rspec-read`, but JVM Squad uses just `rspec`.
19+
rspec-token-suffix: 'rspec'
20+
post-update: |
21+
java -jar rule-api.jar generate -rule XPathCheck
22+
cp sonar-xml-plugin/src/main/resources/org/sonar/l10n/xml/rules/xml/S140.html sonar-xml-plugin/src/main/resources/org/sonar/l10n/xml/rules/xml/XPathCheck.html
23+
cp sonar-xml-plugin/src/main/resources/org/sonar/l10n/xml/rules/xml/S140.json sonar-xml-plugin/src/main/resources/org/sonar/l10n/xml/rules/xml/XPathCheck.json
24+
25+
- name: Check Rule Metadata Changes
7126
run: |
72-
echo "Generated ${{steps.create-pr.outputs.url}}." >> $GITHUB_STEP_SUMMARY
73-
echo "Tip: close and reopen the PR to trigger CI. " >> $GITHUB_STEP_SUMMARY
27+
if [ "${{ steps.update-rule-metadata.outputs.has-changes }}" == "true" ]; then
28+
echo "::notice title=Rule Metadata Changes::Changes detected and PR created: ${{ steps.update-rule-metadata.outputs.pull-request-url }}"
29+
else
30+
echo "::notice title=Rule Metadata Status::No changes to the rules metadata were detected"
31+
fi

0 commit comments

Comments
 (0)