1+ name : Update Static Web Assets Baselines
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ pr_number :
7+ description : ' Pull Request number'
8+ required : true
9+ type : string
10+
11+ jobs :
12+ update-baselines :
13+ runs-on : ubuntu-latest
14+ permissions :
15+ contents : write
16+ pull-requests : write
17+
18+ steps :
19+ - name : Checkout repository
20+ uses : actions/checkout@v4
21+ with :
22+ token : ${{ secrets.GITHUB_TOKEN }}
23+ fetch-depth : 0
24+
25+ - name : Checkout PR branch
26+ run : |
27+ gh pr checkout ${{ github.event.inputs.pr_number }}
28+ env :
29+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
30+
31+ - name : Run build script
32+ id : build
33+ run : |
34+ chmod +x ./build.sh
35+ ./build.sh -c Release
36+ continue-on-error : true
37+
38+ - name : Update baselines
39+ id : update
40+ if : steps.build.outcome == 'success'
41+ run : |
42+ # Set DOTNET_ROOT to the local dotnet installation
43+ export DOTNET_ROOT="$(pwd)/.dotnet"
44+ # Prepend DOTNET_ROOT to PATH
45+ export PATH="$DOTNET_ROOT:$PATH"
46+
47+ # Run the update baselines script
48+ chmod +x src/RazorSdk/update-test-baselines.sh
49+ src/RazorSdk/update-test-baselines.sh
50+ continue-on-error : true
51+
52+ - name : Check for changes
53+ id : check-changes
54+ if : steps.update.outcome == 'success'
55+ run : |
56+ # Check if there are changes to any *.json files under the test folder
57+ if git diff --name-only | grep -E '^test/.*\.json$'; then
58+ echo "changes=true" >> $GITHUB_OUTPUT
59+ else
60+ echo "changes=false" >> $GITHUB_OUTPUT
61+ fi
62+
63+ - name : Commit and push changes
64+ id : commit
65+ if : steps.update.outcome == 'success' && steps.check-changes.outputs.changes == 'true'
66+ run : |
67+ git config --global user.name 'github-actions[bot]'
68+ git config --global user.email 'github-actions[bot]@users.noreply.github.com'
69+
70+ # Create commit with formatted date
71+ COMMIT_DATE=$(date -u +"%Y-%m-%d")
72+ git add test/**/*.json
73+ git commit -m "[Infrastructure] Update baselines $COMMIT_DATE"
74+
75+ # Push to the PR branch
76+ git push
77+ continue-on-error : true
78+
79+ - name : Comment on PR - No changes
80+ if : steps.update.outcome == 'success' && steps.check-changes.outputs.changes == 'false'
81+ run : |
82+ gh pr comment ${{ github.event.inputs.pr_number }} \
83+ --body "No baselines were updated."
84+ env :
85+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
86+
87+ - name : Comment on PR - Changes pushed
88+ if : steps.commit.outcome == 'success'
89+ run : |
90+ gh pr comment ${{ github.event.inputs.pr_number }} \
91+ --body "Baselines updated."
92+ env :
93+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
94+
95+ - name : Comment on PR - Failure
96+ if : steps.build.outcome == 'failure' || steps.update.outcome == 'failure' || (steps.check-changes.outputs.changes == 'true' && steps.commit.outcome == 'failure')
97+ run : |
98+ ERROR_MSG="Update baselines failed"
99+
100+ if [[ "${{ steps.build.outcome }}" == "failure" ]]; then
101+ ERROR_MSG="$ERROR_MSG: Build script failed"
102+ elif [[ "${{ steps.update.outcome }}" == "failure" ]]; then
103+ ERROR_MSG="$ERROR_MSG: Update baselines script failed"
104+ elif [[ "${{ steps.commit.outcome }}" == "failure" ]]; then
105+ ERROR_MSG="$ERROR_MSG: Failed to commit or push changes"
106+ fi
107+
108+ gh pr comment ${{ github.event.inputs.pr_number }} \
109+ --body "$ERROR_MSG"
110+ env :
111+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments