-
Notifications
You must be signed in to change notification settings - Fork 0
54 lines (47 loc) · 1.94 KB
/
update_htpasswd.yaml
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
name: Update htpasswd file
on:
workflow_dispatch:
inputs:
course_code:
description: Code of the course to change the password to
required: true
type: string
concurrency: dscourses-writer
jobs:
write-htpasswd:
name: Write htpasswd
runs-on: ubuntu-latest
env:
DESOTECH_PASSWORD: '${{ secrets.DESOTECH_PASSWORD }}'
steps:
- id: course-code
run: course_code=${{ inputs.course_code }} ; echo lowercase=${course_code,,} >> "$GITHUB_OUTPUT"
- name: Checkout dscourses repository
uses: actions/checkout@v2
with:
token: '${{ secrets.PAT_TOKEN }}'
repository: ${{ github.repository_owner }}/dscourses
path: dscourses
- id: generate_password
run: echo "course_password=$(< /dev/random LC_ALL=C tr -dc _A-Z-a-z-0-9 | head -c7)" >> "$GITHUB_OUTPUT"
- name: Install htpasswd
run: sudo apt-get update -y && sudo apt-get install -y apache2-utils
- name: Write Password
run: |
course_code='${{ steps.course-code.outputs.lowercase }}'
password='${{ steps.generate_password.outputs.course_password }}'
htpasswd -c -b dscourses/$course_code/.htpasswd desotech "$DESOTECH_PASSWORD"
htpasswd -b dscourses/$course_code/.htpasswd "$course_code" "$password"
echo "$password" >> dscourses/$course_code/password.txt
- name: Push Changes
run: |
git -C dscourses config --local user.name 'GitHub Actions'
git -C dscourses config --local user.email [email protected]
git -C dscourses add -A
if git -C dscourses commit -m 'Update htpasswd for ${{ inputs.course_code }}'
then
retries=0
until git -C dscourses push || [ "$retries" -gt 10 ] ; do sleep 5 ; git -C dscourses pull --rebase ; ((retries++)) ; done
else
echo 'Nothing to commit. The site is already up-to-date.'
fi