Skip to content

Commit bf3f940

Browse files
ci: support Netlify via Makefile & .gitignore (#243)
* ci: support Netlify via Makefile & .gitignore * ci: netlify workflows (UNTESTED) * ci: validation workflow (UNTESTED) * ci: update reqs workflow (UNTESTED) * ci: delete netlify workflows (NEW APPROACH COMING) * ci: update reqs workflow (ALLOW TEST) * ci: fix workflow name * fix: workflow typos * chore: auto-update requirements.txt [bot] * refactor: workflows * build: this branch * test: attempt change reqs, expect validation error * fix: unepxcted syntax in workflows * Revert "test: attempt change reqs, expect validation error" This reverts commit c662bd0. * docs: reword [skip ci] * increase Python version support * ci: get python version from pyproject.toml * Revert "increase Python version support" This reverts commit a650f7c. * test: new PR triggering Netlify preview server (#242) * delete unused workflow * ci: remove branch that will be merged soon * docs: explain workflows * chore: delete unnecessary Make command * docs: TESTING * fix: TESTING.md ToC * ci: validate this branch * test: change reqs * ci: skip update-reqs if nothing updated * ci: prettier output for validate-reqs * refactor: requiremnts workflows * fix; workflow bugs * refactor: simpplify reqs-validate * fix: reqs change reverted manually * fix: do not run workflows twice * fix: limit excess workflow runs * refactor: rename workflows and jobs * test: change requirements * Revert "test: change requirements" This reverts commit fbf1e28. --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 5039f41 commit bf3f940

File tree

6 files changed

+151
-51
lines changed

6 files changed

+151
-51
lines changed

.github/workflows/build-pprd.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
- pprd
77
- epic/v3
88
- any/branch-you-want
9-
- fix/docs_dir-not-set
109

1110
jobs:
1211
docker:

.github/workflows/build-preview.yml

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Humans should not manage requirements.txt (bots do)
2+
name: Validate requirements.txt not changed by human
3+
4+
on:
5+
pull_request:
6+
paths: ['requirements.txt']
7+
types: [opened, synchronize, reopened]
8+
9+
jobs:
10+
reject-requirements-drift:
11+
runs-on: ubuntu-latest
12+
13+
# Skip if the last commit was from the bot (prevent unnecessary check)
14+
if: github.event.head_commit.author.name != 'github-actions[bot]'
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0 # full history
21+
22+
- name: Check if requirements.txt was modified unexpectedly
23+
run: |
24+
# For PRs, check against base branch
25+
# For pushes, check last commit
26+
if [ "${{ github.event_name }}" = "pull_request" ]; then
27+
BASE_REF="${{ github.event.pull_request.base.sha }}"
28+
COMPARE_RANGE="$BASE_REF...HEAD"
29+
else
30+
COMPARE_RANGE="HEAD~1..HEAD"
31+
fi
32+
33+
# If requirements.txt modified in that range
34+
if git diff --name-only $COMPARE_RANGE | grep -q "^requirements.txt$"; then
35+
echo "::error::You may NOT edit 'requirements.txt'"
36+
echo "::warning::Undo your changes to requirements.txt, so robot can maintain it."
37+
echo "::notice::To pin dependencies, use 'poetry add <package-name>'."
38+
exit 1
39+
fi
40+
41+
echo "'requirements.txt' unchanged (or only changed by bot)"
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Netlify requires requirements.txt (humans do not)
2+
name: Sync requirements.txt with pyproject.toml
3+
4+
on:
5+
pull_request:
6+
paths: ['pyproject.toml']
7+
types: [opened, synchronize, reopened]
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
detect-requirements-delta:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
has_change: ${{ steps.detect.outputs.has_change }}
17+
18+
# Skip if the last commit was from the bot (prevent infinite loops)
19+
if: github.event.head_commit.author.name != 'github-actions[bot]'
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v4
24+
with:
25+
ref: ${{ github.head_ref || github.ref_name }}
26+
27+
- name: Set up Python
28+
uses: actions/setup-python@v5
29+
with:
30+
python-version-file: 'pyproject.toml'
31+
32+
- name: Install Poetry
33+
run: pip install poetry
34+
35+
- name: Detect whether requirements.txt has change
36+
id: detect
37+
run: |
38+
output=$(make requirements.txt 2>&1)
39+
echo "$output"
40+
41+
# Check whether Make output suggests file is up to date
42+
if echo "$output" | grep -qi "up to date\|up-to-date\|already up to date"; then
43+
echo "has_change=false" >> $GITHUB_OUTPUT
44+
echo "::notice::requirements.txt seems up to date"
45+
else
46+
echo "has_change=true" >> $GITHUB_OUTPUT
47+
fi
48+
49+
commit-requirements-delta:
50+
runs-on: ubuntu-latest
51+
needs: detect-requirements-delta
52+
if: needs.detect-requirements-delta.outputs.has_change == 'true'
53+
54+
steps:
55+
- name: Checkout code
56+
uses: actions/checkout@v4
57+
with:
58+
ref: ${{ github.head_ref || github.ref_name }}
59+
token: ${{ secrets.GITHUB_TOKEN }}
60+
61+
- name: Set up Python
62+
uses: actions/setup-python@v5
63+
with:
64+
python-version-file: 'pyproject.toml'
65+
66+
- name: Install Poetry
67+
run: pip install poetry
68+
69+
- name: Generate requirements.txt
70+
run: make requirements.txt
71+
72+
- name: Configure Git
73+
run: |
74+
git config user.name "github-actions[bot]"
75+
git config user.email "github-actions[bot]@users.noreply.github.com"
76+
77+
- name: Commit requirements.txt if changed
78+
run: |
79+
git add -f requirements.txt
80+
if git diff --staged --quiet; then
81+
echo "No changes to requirements.txt"
82+
else
83+
git commit -m "chore: auto-update requirements.txt [bot]"
84+
git push
85+
fi

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# WARNING: Using `docker-compose` is deprecated
22
DOCKER_COMPOSE_CMD := $(shell if command -v docker-compose > /dev/null; then echo "docker-compose"; else echo "docker compose"; fi)
33

4+
5+
requirements.txt: poetry.lock
6+
pip install --user poetry-plugin-export \
7+
&& poetry export -f requirements.txt --output requirements.txt \
8+
&& pip uninstall --yes poetry-plugin-export
9+
10+
411
.PHONY: build
512
build:
613
$(DOCKER_COMPOSE_CMD) -f ./docker-compose.yml build

TESTING.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
# How to Test
22

3-
## Local Server
3+
- [On Free Machine](#on-free-machine)
4+
- [On Your Machine](#on-your-machine)
5+
- [On Our Machine](#on-our-machine)
46

5-
> [!WARNING]
6-
> Testing is manual and requires using a command prompt.
7+
## On Free Machine
8+
9+
> [!TIP]
10+
> Create a pull request; automatically get a remote preview server.
711
8-
You can [test with **PIP** or **Poetry** or **Docker** or **Make**](https://tacc.github.io/mkdocs-tacc/test/#test-locally) as a client.
12+
## On Your Machine
913

10-
## Remote Server
14+
> [!NOTE]
15+
> Run a server manually or programatically on your machine.
1116
12-
> [!WARNING]
13-
> Your test may be overridden by others working on the same test server.
17+
You can [test with **PIP** or **Poetry** or **Docker** or **Make**](https://tacc.github.io/mkdocs-tacc/test/#test-locally).
1418

15-
Deploy to our test server:
19+
## On Our Machine
20+
21+
> [!WARNING]
22+
> Only authorized contributors may deploy to our test server.
1623
1724
0. Have a branch with changes ready to deploy.
18-
1. On your branch, edit the [pre-prod workflow config](./.github/workflows/build-pprd.yml) `branches:` list.
25+
1. On your branch, edit the [pre-prod workflow config](./.github/workflows/build-pprd.yml) `branches:` list to include your branch.
1926
2. Commit the change to trigger the workflow.
2027
3. Wait for [GitHub action](https://github.com/DesignSafe-CI/ds-user-guide/actions) to complete.
2128
4. Load https://pprd.designsafe-ci.org/user-guide/.
2229

23-
> [!TIP]
24-
> In the future, we will offer a dedicated test server. Task is pending [issue #61](https://github.com/DesignSafe-CI/DS-User-Guide/issues/61).
30+
> [!CAUTION]
31+
> Others can override your test by deploying to this server.

0 commit comments

Comments
 (0)