46
value: ${{ jobs.Prepare.outputs.reportFile }}
48
value: ${{ jobs.Prepare.outputs.changedFiles }}
50
value: ${{ jobs.Prepare.outputs.changedPythonFiles }}
52
value: ${{ jobs.Prepare.outputs.changedCppFiles }}
58
isPR: ${{ github.event_name == 'pull_request' }}
59
isPush: ${{ github.event_name == 'push' }}
61
reportdir: /tmp/report/
62
reportfilename: ${{ inputs.artifactBasename }}-report.md
63
runs-on: ubuntu-latest
68
reportFile: ${{ steps.Init.outputs.reportFile }}
69
changedFiles: ${{ steps.Output.outputs.changedFiles }}
70
changedPythonFiles: ${{ steps.Output.outputs.changedPythonFiles }}
71
changedCppFiles: ${{ steps.Output.outputs.changedCppFiles }}
74
- name: Make needed directories, files and initializations
77
mkdir -p ${{ env.logdir }}
78
mkdir -p ${{ env.reportdir }}
80
touch ${{ env.logdir }}changedFiles.lst ${{ env.logdir }}changedCppFiles.lst ${{ env.logdir }}changedPythonFiles.lst
81
echo "reportFile=${{ env.reportfilename }}" >> $GITHUB_OUTPUT
82
- name: Determine base and head SHA in case of PR
83
if: env.isPR == 'true'
85
baseSha=${{ github.event.pull_request.base.sha }}
86
headSha=${{ github.event.pull_request.head.sha }}
87
echo "baseSha=$baseSha" >> $GITHUB_ENV
88
echo "headSha=$headSha" >> $GITHUB_ENV
89
echo "This CI run is performed on a Pull Request" | tee -a ${{env.reportdir}}${{ env.reportfilename }}
90
echo "Base SHA is $baseSha, Head SHA is $headSha" | tee -a ${{env.reportdir}}${{ env.reportfilename }}
91
- name: Check if PR has been recently rebased
92
if: env.isPR == 'true'
93
continue-on-error: ${{ inputs.dontFailOnOldRebase }}
95
baseDate=$(curl -H "Accept: application/vnd.github+json" -H "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" $GITHUB_API_URL/repos/$GITHUB_REPOSITORY/commits/$baseSha | jq -r '.commit.committer.date')
96
dateDiff=$(( ( $(date +%s) - $(date -d $baseDate +%s) ) / 3600 ))
97
echo "Pull request is based on a $dateDiff hour-old commit" | tee -a ${{env.reportdir}}${{ env.reportfilename }}
98
# Exit the step with appropriate code
99
if [ $dateDiff -gt ${{ inputs.maxRebaseHours }} ]
101
echo -n ":warning: Pull request should be rebased" | tee -a ${{env.reportdir}}${{ env.reportfilename }}
104
- name: Determine base and head SHA in case of push
105
if: env.isPush == 'true'
107
baseSha=${{ github.event.before }}
108
headSha=${{ github.event.after }}
109
echo "headSha=$headSha" >> $GITHUB_ENV
110
if [ $baseSha -eq 0 ]
112
echo "This CI run is performed on a Push that created a new branch : files changed will be ignored" | tee -a ${{env.reportdir}}${{ env.reportfilename }}
113
echo "Head SHA is $headSha" | tee -a ${{env.reportdir}}${{ env.reportfilename }}
114
echo "isPush='false'" >> $GITHUB_ENV
116
echo "This CI run is performed on a Push" | tee -a ${{env.reportdir}}${{ env.reportfilename }}
117
echo "Base SHA is $baseSha, Head SHA is $headSha" | tee -a ${{env.reportdir}}${{ env.reportfilename }}
118
echo "baseSha=$baseSha" >> $GITHUB_ENV
120
- name: Get compare between head and base
121
if: env.isPR == 'true' || env.isPush == 'true'
123
echo "$GITHUB_API_URL/repos/$GITHUB_REPOSITORY/compare/$baseSha...$headSha"
124
curl -H "Accept: application/vnd.github+json" -H "authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" $GITHUB_API_URL/repos/$GITHUB_REPOSITORY/compare/$baseSha...$headSha > ${{ env.logdir }}compare.json
125
- name: Get number of commits in the changeset
126
if: env.isPR == 'true' || env.isPush == 'true'
128
commitCnt=$(jq -re '.ahead_by' ${{ env.logdir }}compare.json)
129
echo "Changeset is composed of $commitCnt commit(s)" | tee -a ${{env.reportdir}}${{ env.reportfilename }}
130
- name: Get files modified in changeset
131
if: env.isPR == 'true' || env.isPush == 'true'
133
jq '.files[] | if .status != "removed" then .filename else empty end' ${{ env.logdir }}compare.json > ${{ env.logdir }}changedFiles.lst
134
grep -E '\.(py|py3)"' ${{ env.logdir }}changedFiles.lst > ${{ env.logdir }}changedPythonFiles.lst || true
135
grep -E '\.(c|c\+\+|cc|cpp|cu|cuh|cxx|h|h\+\+|hh|hpp|hxx)"' ${{ env.logdir }}changedFiles.lst > ${{ env.logdir }}changedCppFiles.lst || true
137
echo "::group::Modified files in changeset (removed files are ignored) :" ; cat ${{ env.logdir }}changedFiles.lst ; echo "::endgroup::"
138
echo "<details><summary>Modified files (removed files are ignored):</summary>" >> ${{env.reportdir}}${{ env.reportfilename }}
139
cat ${{ env.logdir }}changedFiles.lst >> ${{env.reportdir}}${{ env.reportfilename }}
140
echo "</details>" >> ${{env.reportdir}}${{ env.reportfilename }}
141
echo "" >> ${{env.reportdir}}${{ env.reportfilename }}
142
- name: Transmitting outputs
145
echo "changedFiles=$(cat ${{ env.logdir }}changedFiles.lst | tr '\n' ' ')" >> $GITHUB_OUTPUT
146
echo "changedPythonFiles=$(cat ${{ env.logdir }}changedPythonFiles.lst | tr '\n' ' ')" >> $GITHUB_OUTPUT
147
echo "changedCppFiles=$(cat ${{ env.logdir }}changedCppFiles.lst | tr '\n' ' ')" >> $GITHUB_OUTPUT
148
echo "" >> $GITHUB_OUTPUT
151
uses: actions/upload-artifact@v4
153
name: ${{ inputs.artifactBasename }}-Logs
156
- name: Upload report
158
uses: actions/upload-artifact@v4
160
name: ${{ env.reportfilename }}
162
${{env.reportdir}}${{ env.reportfilename }}