risp/.gitea/workflows/update.yml

56 lines
1.7 KiB
YAML
Raw Normal View History

2024-10-17 18:34:00 +02:00
name: Update CI/CD Pipeline
on:
schedule:
2024-10-17 20:00:11 +02:00
- cron: '@daily'
2024-10-17 19:09:19 +02:00
env:
GITEATOKEN: ${{ secrets.GITEATOKEN }}
2024-10-17 18:34:00 +02:00
jobs:
update:
runs-on: ubuntu-latest
container: git.hofer.link/ruderverein-donau-linz/rowing-ci:20240215
steps:
- uses: actions/checkout@v3
- name: Cache Cargo dependencies
uses: Swatinem/rust-cache@v2
2024-10-17 18:42:28 +02:00
- name: Run Update Script
2024-10-17 18:34:00 +02:00
run: ./update_laws.sh
2024-10-17 18:42:28 +02:00
- name: Check for changes and create branch if necessary
run: |
git config --global user.email "ci-bot@example.com"
git config --global user.name "CI Bot"
if [ -n "$(git status --porcelain)" ]; then
echo "Changes detected. Committing and preparing to push."
2024-10-17 19:53:15 +02:00
if git ls-remote --exit-code --heads origin update-branch; then
echo "Branch 'update-branch' exists. Checking it out."
2024-10-17 19:56:49 +02:00
git fetch
git checkout remote/update-branch
2024-10-17 19:53:15 +02:00
else
echo "Branch 'update-branch' does not exist. Creating it."
git checkout -b update-branch
fi
2024-10-17 18:42:28 +02:00
git add .
git commit -m "Automated update of laws"
2024-10-17 18:51:30 +02:00
git push origin update-branch
2024-10-17 18:42:28 +02:00
else
echo "No changes detected."
exit 0
fi
- name: Create Pull Request
if: success()
run: |
if [ -n "$(git log origin/main..HEAD)" ]; then
2024-10-17 19:02:48 +02:00
curl -X POST "https://git.hofer.link/api/v1/repos/philipp/risp/pulls" \
2024-10-17 18:59:36 +02:00
-H "Authorization: token $GITEATOKEN" \
2024-10-17 18:42:28 +02:00
-H "Content-Type: application/json" \
2024-10-17 19:53:15 +02:00
-d '{"title":"Update laws","head":"update-branch","base":"main","body":"Automated update of laws.", "assignee": "philipp"}'
2024-10-17 18:42:28 +02:00
else
echo "No changes to create a pull request."
fi