Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add snapshot CI #166

Merged
merged 5 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/scripts/check_integration_branch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

repo=$1
core_version=$2

# Add "-SNAPSHOT" to powsybl-core version if not already there
core_snapshot_version=$(echo "$core_version" | grep -q SNAPSHOT && echo "$core_version" || echo "$core_version-SNAPSHOT")

# Find if an integration branch exists
INTEGRATION_BRANCH=$(git ls-remote --heads "$repo" | grep -E "refs/heads/integration/powsyblcore-$core_snapshot_version" | sed 's/.*refs\/heads\///')
if [ -n "$INTEGRATION_BRANCH" ]; then
echo "SNAPSHOT VERSION EXIST: $INTEGRATION_BRANCH"
echo "INTEGRATION_BRANCH=$INTEGRATION_BRANCH" >> "$GITHUB_ENV"
else
echo "No SNAPSHOT branch found"
echo "INTEGRATION_BRANCH=main" >> "$GITHUB_ENV"
fi
200 changes: 200 additions & 0 deletions .github/workflows/snapshot-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
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: Determine workflow status
id: workflow_status
run: |
if [ "${{ job.status }}" == "success" ]; then
echo "icon=✅" >> $GITHUB_OUTPUT
echo "status=Successful" >> $GITHUB_OUTPUT
else
echo "icon=❌" >> $GITHUB_OUTPUT
echo "status=Failed" >> $GITHUB_OUTPUT
fi

- 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: 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\nSee 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
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 }}
Loading