SAMS Data Synchronisation #4052
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: SAMS Data Synchronisation | |
concurrency: | |
group: "sams" | |
cancel-in-progress: false | |
on: | |
schedule: | |
- cron: 27 11-23 * * 0,1,6 # Every hour, between 11 AM and 11 PM, Saturday-Monday | |
workflow_dispatch: | |
env: | |
GITHUB_TOKEN: ${{ secrets.BK_GH_PAT }} | |
SAMS_KEY: ${{ secrets.SAMS_API }} | |
SAMS_URL: "https://www.volleyball-baden.de" | |
SAMS_CLUBID: "471" | |
# paths and files reused throughout the workflow | |
SAMS_CLUB_XML: _sams/xml/club.xml | |
SAMS_MATCHES_XML: _sams/xml/matches/ | |
jobs: | |
######################## | |
### CLUB DATA UPDATE ### | |
######################## | |
Get-Teams: | |
name: Get Teams | |
runs-on: ubuntu-latest | |
outputs: | |
teamids: ${{steps.teamid-list.outputs.teamids}} # outputs team IDs in the form of [123,456,789] | |
steps: | |
- name: Checkout Source Code | |
uses: actions/checkout@v3 | |
with: | |
token: ${{env.GITHUB_TOKEN}} | |
fetch-depth: 0 | |
- name: Setup Git Config | |
run: | | |
git config user.name "GitHub Actions Bot" | |
git config user.email "<>" | |
- name: Query SAMS for Club Data | |
id: sams_query_club | |
run: | | |
mkdir -p $(dirname ${{env.SAMS_CLUB_XML}}) | |
curl -o ${{env.SAMS_CLUB_XML}} "$SAMS_URL/xml/sportsclub.xhtml?apiKey=$SAMS_KEY&sportsclubId=$SAMS_CLUBID" -f --retry 10 --retry-delay 60 --connect-timeout 30 | |
- name: Check for maintenance mode | |
id: sams_maintenance_check | |
if: steps.sams_query_club.conclusion == 'success' | |
run: | | |
if grep -q "Wartung" ${{env.SAMS_CLUB_XML}}; then | |
echo "🛑 HALT! SAMS seems to be in maintenance mode. 🛑" | |
exit 1 | |
fi | |
if grep -q . ${{env.SAMS_CLUB_XML}}; then | |
echo "✅ file seems fine" | |
else | |
echo "🛑 HALT! SAMS seems to be in maintenance mode. 🛑" | |
exit 1 | |
fi | |
- name: Isolate Teams from XML # this reads the XML file and extracts the team IDs | |
id: teamids-from-club | |
if: steps.sams_maintenance_check.conclusion == 'success' | |
uses: mavrosxristoforos/[email protected] | |
with: | |
xml-file: "_sams/xml/club.xml" | |
xpath: "/sportsclub/teams/team/seasonTeamId" | |
- name: Transform MatchSeries IDs | |
id: teamid-list | |
if: steps.teamids-from-club.conclusion == 'success' | |
run: echo "teamids=[${{steps.teamids-from-club.outputs.info}}]" >> $GITHUB_OUTPUT # transform IDs from "123,456,789" to "[123,456,789]" | |
- name: Git Commit & Push | |
if: steps.sams_maintenance_check.conclusion == 'success' | |
continue-on-error: true | |
run: | | |
git add "${{env.SAMS_CLUB_XML}}" | |
git commit -m "sams raw club update" || true | |
git pull --rebase --quiet | |
git push origin --all --quiet | |
###################### | |
### MATCHES UPDATE ### | |
###################### | |
Get-Matches: | |
name: Get Matches | |
needs: Get-Teams | |
continue-on-error: true # if one team fails, the flow should continue | |
strategy: | |
max-parallel: 3 | |
matrix: | |
teams: ${{fromJSON(needs.Get-Teams.outputs.teamids)}} | |
outputs: | |
upload_required: ${{ steps.upload_status.outputs.required }} # controls the artifact download before commit | |
runs-on: ubuntu-latest | |
steps: | |
- name: Query SAMS # make the API call to the SAMS server and save it as XML | |
id: query_sams | |
run: | | |
mkdir -p ${{env.SAMS_MATCHES_XML}} | |
curl -o ${{env.SAMS_MATCHES_XML}}${{matrix.teams}}.xml "$SAMS_URL/xml/matches.xhtml?apiKey=$SAMS_KEY&teamId=${{matrix.teams}}" -f --retry 5 --retry-delay 60 | |
- name: Upload Artifact (SAMS XML) | |
id: upload | |
uses: actions/upload-artifact@v3 | |
with: | |
name: raw_sams_matches_xml | |
path: ${{env.SAMS_MATCHES_XML}}${{matrix.teams}}.xml | |
- name: Upload Status | |
id: upload_status | |
if: steps.upload.conclusion == 'success' | |
run: echo "required=yes" >> $GITHUB_OUTPUT | |
#################### | |
### GIT PROCESS ### | |
################### | |
Git-Update-Matches: | |
name: Git Update | |
needs: | |
- Get-Matches | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Source Code | |
uses: actions/checkout@v3 | |
with: | |
token: ${{env.GITHUB_TOKEN}} | |
fetch-depth: 0 | |
- name: Download Matches Exports (XML) | |
if: contains(needs.Get-Matches.outputs.upload_required, 'yes') | |
uses: actions/download-artifact@v3 | |
with: | |
name: raw_sams_matches_xml | |
path: ${{env.SAMS_MATCHES_XML}} | |
- name: Setup Git Config | |
run: | | |
git config user.name "GitHub Actions Bot" | |
git config user.email "<>" | |
- name: Git Commit Matches | |
continue-on-error: true | |
run: | | |
git add "${{env.SAMS_MATCHES_XML}}*" | |
git commit -m "sams matches update" || true | |
- name: Git Push | |
continue-on-error: true | |
run: | | |
git pull --rebase | |
git push origin --all --quiet |