Skip to content

Commit 189e967

Browse files
committed
restructure deploy action
It is cleaner to run all tasks in one matrix. We add `main` as a version but sync to the server without a version subdirectory. We exclude the version subdirectories from the `main` rsync --delete because matrix jobs are not guaranteed to run in a particular order. If we don't do this it can wipe out the versions after they are copied over.
1 parent b8fc1d6 commit 189e967

File tree

2 files changed

+18
-51
lines changed

2 files changed

+18
-51
lines changed

.github/workflows/deploy.yml

Lines changed: 16 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,20 @@ jobs:
2626
quoted+=("\"$line\"")
2727
done
2828
str=$( IFS=$','; echo "${quoted[*]}" )
29-
echo "versions=[$str]" >> $GITHUB_OUTPUT
29+
echo "versions=[\"main\",$str]" >> $GITHUB_OUTPUT
3030
31-
compile-latest:
31+
compile:
3232
runs-on: ubuntu-latest
33+
needs: get-versions
34+
strategy:
35+
matrix:
36+
version: ${{ fromJSON(needs.get-versions.outputs.versions) }}
3337
steps:
3438

3539
- name: Check out code
3640
uses: actions/checkout@v4
41+
with:
42+
ref: ${{ matrix.version }}
3743

3844
- name: Set up Python 3.9
3945
uses: actions/setup-python@v2
@@ -55,68 +61,29 @@ jobs:
5561
5662
- name: Compile site
5763
run: |
58-
python generate.py
64+
python generate.py ${{ matrix.version }}
5965
6066
- uses: stefanzweifel/git-auto-commit-action@v5
6167
with:
6268
commit_user_name: BookWyrm Bot
63-
commit_message: deploy latest
69+
commit_message: deploy versions
6470
commit_author: BookWyrm Bot <joinbookwyrm@users.noreply>
6571

66-
- name: Deploy to server
67-
id: deploy-latest
72+
- name: Deploy latest to server
73+
if: ${{ matrix.version == 'main' }}
74+
id: deploy-versions
6875
uses: Pendect/action-rsyncer@v2.0.0
6976
env:
7077
DEPLOY_KEY: ${{secrets.DEPLOY_KEY}}
7178
with:
72-
flags: '-avzr --delete'
79+
flags: '-avzr --delete --exclude="v*[0-9\.]/**"'
7380
options: ''
7481
ssh_options: ''
7582
src: 'site/'
7683
dest: 'mouse@docs.joinbookwyrm.com:/var/www/docs-bookwyrm/html'
7784

78-
compile-versions:
79-
runs-on: ubuntu-latest
80-
needs: get-versions
81-
strategy:
82-
matrix:
83-
version: ${{ fromJSON(needs.get-versions.outputs.versions) }}
84-
steps:
85-
86-
- name: Check out code
87-
uses: actions/checkout@v4
88-
with:
89-
ref: ${{ matrix.version }}
90-
91-
- name: Set up Python 3.9
92-
uses: actions/setup-python@v2
93-
with:
94-
python-version: 3.9
95-
96-
- name: Install Dev Dependencies
97-
run: |
98-
sudo apt-get install gettext
99-
100-
- name: Install Python Dependencies
101-
run: |
102-
python -m pip install --upgrade pip
103-
pip install -r requirements.txt
104-
105-
- name: Process translations
106-
run: |
107-
./bw-dev messages:update
108-
109-
- name: Compile site
110-
run: |
111-
python generate.py ${{ matrix.version }}
112-
113-
- uses: stefanzweifel/git-auto-commit-action@v5
114-
with:
115-
commit_user_name: BookWyrm Bot
116-
commit_message: deploy versions
117-
commit_author: BookWyrm Bot <joinbookwyrm@users.noreply>
118-
119-
- name: Deploy to server
85+
- name: Deploy versions to server
86+
if: ${{ matrix.version != 'main' }}
12087
id: deploy-versions
12188
uses: Pendect/action-rsyncer@v2.0.0
12289
env:

generate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ def format_markdown(file_path):
124124

125125

126126
if __name__ == "__main__":
127-
# when we generate for older versions we need to change the page links
128-
version = sys.argv[1] if len(sys.argv) > 1 else False
127+
# when we generate for versions we need to change the page links
128+
version = sys.argv[1] if (len(sys.argv) > 1 and sys.argv[1] != "main") else False
129129
# iterate through each locale
130130
for locale in i18n.locales_metadata:
131131
SLUG = locale["slug"]

0 commit comments

Comments
 (0)