-
Notifications
You must be signed in to change notification settings - Fork 1
137 lines (114 loc) · 4.92 KB
/
update_sa11y.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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"