Update sa11y #70
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: 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 | |
rm -rf sa11y-* | |
- 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' | |
id: add_files | |
run: | | |
git add assets/vendor/sa11y .sa11y_version | |
if [ -z "$(git status --porcelain)" ]; then | |
echo "No changes detected, exiting." | |
echo "changes_detected=false" >> $GITHUB_OUTPUT | |
exit 0 | |
else | |
echo "changes_detected=true" >> $GITHUB_OUTPUT | |
fi | |
git status | |
- name: Commit and push changes | |
if: steps.add_files.outputs.changes_detected == 'true' | |
run: | | |
BRANCH_NAME="update-sa11y-${{ steps.get_latest_release.outputs.tag_name }}" | |
git checkout -b "$BRANCH_NAME" | |
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: steps.add_files.outputs.changes_detected == 'true' | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
BRANCH_NAME: ${{ steps.get_latest_release.outputs.tag_name }} | |
run: | | |
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. Maybe a Pull request with this name already exists. This needs to be checked manually" | |
else | |
echo "Pull request created: $PR_URL" | |
fi |