Skip to content

Update sa11y

Update sa11y #59

Workflow file for this run

name: Update sa11y
on:
schedule:
- cron: '0 0 * * 1' # Läuft jeden Montag um Mitternacht
workflow_dispatch: # Ermöglicht manuelles Auslösen
jobs:
update-sa11y:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Get latest sa11y release tag
id: get_latest_release
uses: actions/github-script@v6
with:
script: |
try {
const latestRelease = await github.rest.repos.getLatestRelease({
owner: 'ryersondmp',
repo: 'sa11y'
});
core.setOutput("tag_name", latestRelease.data.tag_name);
} catch (error) {
core.setFailed(`Failed to get the latest release: ${error.message}`);
}
- name: Check if update is needed
id: check_update
run: |
if [ ! -f .sa11y_version ]; then
echo "No version file found, creating one."
echo "none" > .sa11y_version
fi
CURRENT_VERSION=$(cat .sa11y_version)
echo "Current version: $CURRENT_VERSION"
if [ "$CURRENT_VERSION" = "${{ steps.get_latest_release.outputs.tag_name }}" ]; then
echo "Already up-to-date."
exit 0 # Beenden Sie den Job, wenn keine Aktualisierung erforderlich ist
fi
echo "New version found: ${{ steps.get_latest_release.outputs.tag_name }}"
- name: Check if branch already exists
id: check_branch
run: |
BRANCH_NAME="update-sa11y-${{ steps.get_latest_release.outputs.tag_name }}"
if git ls-remote --heads origin "$BRANCH_NAME" | grep "$BRANCH_NAME" > /dev/null; then
echo "Branch $BRANCH_NAME already exists."
echo "branch_exists=true" >> $GITHUB_ENV
else
echo "branch_exists=false" >> $GITHUB_ENV
fi
- name: Download and extract latest sa11y release
if: env.branch_exists == 'false'
run: |
TAG_NAME="${{ steps.get_latest_release.outputs.tag_name }}"
DOWNLOAD_URL="https://github.com/ryersondmp/sa11y/archive/refs/tags/${TAG_NAME}.zip"
# Versuche, die Datei herunterzuladen und führe Fehlerbehandlung durch
if ! curl -L "$DOWNLOAD_URL" -o sa11y.zip; then
echo "Failed to download sa11y.zip"
exit 1
fi
# Überprüfen, ob die Datei existiert und erfolgreich heruntergeladen wurde
if [ ! -f sa11y.zip ]; then
echo "sa11y.zip does not exist."
exit 1
fi
unzip -o sa11y.zip
rm -rf assets/vendor/sa11y
mkdir -p assets/vendor/sa11y
mv sa11y-*/** assets/vendor/sa11y/
# Löschen der ZIP-Datei und des temporären entpackten Ordners
rm sa11y.zip # Löschen der ZIP-Datei nach dem Entpacken
rm -rf sa11y-* # Löschen des temporären entpackten Ordners
- name: Save the new version
if: env.branch_exists == 'false'
run: echo "${{ steps.get_latest_release.outputs.tag_name }}" > .sa11y_version
- name: Configure Git
if: env.branch_exists == 'false'
run: |
git config --global user.name "GitHub Action"
git config --global user.email "[email protected]"
- name: Add files to Git
if: env.branch_exists == 'false'
run: |
git add assets/vendor/sa11y .sa11y_version
# Überprüfen, ob Dateien zum Commit hinzugefügt wurden
if [ -z "$(git status --porcelain)" ]; then
echo "No changes detected, exiting."
exit 0
fi
git status # Überprüfen des Status, um sicherzustellen, dass die Dateien hinzugefügt wurden
- name: Commit and push changes
if: env.branch_exists == 'false'
run: |
BRANCH_NAME="update-sa11y-${{ steps.get_latest_release.outputs.tag_name }}"
git checkout -b "$BRANCH_NAME"
# Prüfen, ob es tatsächlich Änderungen gibt
if git diff-index --quiet HEAD --; then
echo "No changes to commit."
exit 0
fi
git commit -m "Update sa11y to version ${{ steps.get_latest_release.outputs.tag_name }}"
git push --force origin "$BRANCH_NAME"
- name: Create Pull Request
if: env.branch_exists == 'false' && steps.commit_and_push.changes_detected == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH_NAME: ${{ steps.get_latest_release.outputs.tag_name }}
run: |
# Versuche, eine Pull Request zu erstellen und führe Fehlerbehandlung durch
PR_URL=$(gh pr create --title "Update sa11y to version ${{ steps.get_latest_release.outputs.tag_name }}" --body "This PR updates sa11y to the latest version and replaces the content of the assets folder." --head "update-sa11y-${BRANCH_NAME}" --base main || echo "Failed to create PR")
if [ "$PR_URL" = "Failed to create PR" ]; then
echo "Error creating Pull Request"
exit 1
fi
echo "Pull request created: $PR_URL"