-
Notifications
You must be signed in to change notification settings - Fork 1
201 lines (178 loc) · 7.4 KB
/
snapshot-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
name: Snapshot CI
on:
workflow_dispatch:
schedule:
- cron: '20 3 * * *'
jobs:
build_powsybl_afs:
name: Build Java ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
fail-fast: false
defaults:
run:
shell: bash
steps:
- name: Set up JDK 17
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1
with:
distribution: 'temurin'
java-version: '17'
# Define script path variable
- name: Set up script path
run: |
SCRIPTS_PATH="${GITHUB_WORKSPACE}/scripts/.github/workflows/scripts"
if [[ "${{ matrix.os }}" == "windows-latest" ]]; then
SCRIPTS_PATH=$(echo "$SCRIPTS_PATH" | sed 's/\\/\//g')
fi
echo "SCRIPTS_PATH=$SCRIPTS_PATH" >> $GITHUB_ENV
# Build powsybl-core on main branch
- name: Checkout core sources
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
with:
repository: powsybl/powsybl-core
ref: main
path: powsybl-core
- name: Build powsybl-core
run: mvn -batch-mode --no-transfer-progress clean install -DskipTests
working-directory: ./powsybl-core
- name: Get powsybl-core version
run: echo "CORE_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)" >> $GITHUB_ENV
working-directory: ./powsybl-core
# Checkout script
# The script check_integration_branch.sh is located in the workflow folder of the repository
# It is necessary for checking out the integration branch if it exists
- name: Checkout script
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
with:
sparse-checkout: |
.github
sparse-checkout-cone-mode: false
path: scripts
# Build powsybl-afs
- name: Checking for powsybl-afs snapshot branch
run: ${{ env.SCRIPTS_PATH }}/check_integration_branch.sh "https://github.com/powsybl/powsybl-afs.git" ${{ env.CORE_VERSION }}
- name: Checkout powsybl-afs
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
with:
repository: powsybl/powsybl-afs
ref: ${{ env.INTEGRATION_BRANCH }}
path: powsybl-afs
submodules: true
- name: update pom.xml
run: mvn versions:set-property -Dproperty=powsyblcore.version -DnewVersion=$CORE_VERSION -DgenerateBackupPoms=false
working-directory: ./powsybl-afs
- name: Build with Maven (Ubuntu)
if: matrix.os == 'ubuntu-latest'
working-directory: ./powsybl-afs
run: ./mvnw --batch-mode -Pjacoco install
- name: Build with Maven (Windows)
if: matrix.os == 'windows-latest'
working-directory: .\powsybl-afs
run: mvnw.cmd --batch-mode install
shell: cmd
- name: Store job result
if: always()
run: |
echo "${{ matrix.os }}=${{ job.status }}" >> job_result_${{ matrix.os }}.txt
- name: Upload job result
if: always()
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # 4.3.3
with:
name: job-results_${{ matrix.os }}
path: job_result_${{ matrix.os }}.txt
outputs:
core-version: ${{ env.CORE_VERSION }}
afs-branch: ${{ env.INTEGRATION_BRANCH }}
# Slack notification
notify_slack:
needs: build_powsybl_afs
runs-on: ubuntu-latest
if: always()
steps:
- name: Download job results
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
- name: Combine job results
run: |
for dir in job-results_*; do
cat "$dir"/* >> combined_job_results.txt
done
- name: Determine workflow status
id: workflow_status
run: |
if grep -q "failure" combined_job_results.txt; then
echo "icon=❌" >> $GITHUB_OUTPUT
echo "status=Failed" >> $GITHUB_OUTPUT
else
echo "icon=✅" >> $GITHUB_OUTPUT
echo "status=Successful" >> $GITHUB_OUTPUT
fi
- name: Format job results
id: format_results
run: |
formatted=""
while IFS='=' read -r os status; do
icon=$([ "$status" == "success" ] && echo ":white_check_mark:" || echo ":x:")
formatted+="${icon} Build powsybl-afs on *${os}*\\n"
done < combined_job_results.txt
formatted="${formatted%\\n}" # Remove the last newline
echo "formatted_results=${formatted}" >> $GITHUB_OUTPUT
- name: Prepare Slack payload
id: prepare_payload
run: |
if [ "${{ steps.workflow_status.outputs.status }}" == "Successful" ]; then
echo 'payload<<EOF' >> $GITHUB_OUTPUT
echo '{
"attachments": [{
"color": "#319f4b",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "${{ steps.workflow_status.outputs.icon }} *${{ steps.workflow_status.outputs.status }} workflow: Snapshot-CI on <https://github.com/powsybl/powsybl-afs|powsybl-afs>*\n\nBranch built: ${{ needs.build_powsybl_afs.outputs.afs-branch }}\nPowSyBl-Core version used: ${{ needs.build_powsybl_afs.outputs.core-version }}\n\nSee logs on <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|GitHub>"
}
}
]
}]
}' >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
else
echo 'payload<<EOF' >> $GITHUB_OUTPUT
echo '{
"attachments": [{
"color": "#f64538",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "${{ steps.workflow_status.outputs.icon }} *${{ steps.workflow_status.outputs.status }} workflow: Snapshot-CI on <https://github.com/powsybl/powsybl-afs|powsybl-afs>*\n\nBranch built: ${{ needs.build_powsybl_afs.outputs.afs-branch }}\nPowSyBl-Core version used: ${{ needs.build_powsybl_afs.outputs.core-version }}"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Workflow details:*\n\n${{ steps.format_results.outputs.formatted_results }}\n\n@channel - See logs on <https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}|GitHub>"
}
}
]
}]
}' >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
fi
- name: Send Slack Notification
uses: 8398a7/action-slack@28ba43ae48961b90635b50953d216767a6bea486 # v3.16.2
if: ${{ steps.workflow_status.outputs.status != 'Successful' || github.event_name == 'workflow_dispatch' }}
with:
author_name: 'powsybl-afs on GitHub'
status: custom
custom_payload: ${{ steps.prepare_payload.outputs.payload }}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_POWSYBL_WEBHOOK_URL }}