Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .actrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-P ubuntu-latest=catthehacker/ubuntu:act-latest
65 changes: 40 additions & 25 deletions .github/workflows/labs_test.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# This workflow can be tested with `act`: .github/workflows/tests/test_labs_test.sh

name: Test changed Lab pages

on:
Expand All @@ -8,44 +10,52 @@ jobs:
test-changed-labs:
runs-on: ubuntu-latest
steps:
- name: Checkout base branch
- name: Checkout repository
uses: actions/checkout@v3
with:
repository: ${{ github.repository }}
ref: main
path: base
fetch-depth: 0 # ensure full history for merge-base diff

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.13'

- name: Checkout base branch
uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.base.repo.full_name }}
ref: ${{ github.event.pull_request.base.ref }}
path: base

- name: Checkout head branch
uses: actions/checkout@v3
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
ref: ${{ github.event.pull_request.head.ref }}
path: head

- name: Get list of changed files
id: changed-files
run: |
cd head
git remote add upstream https://github.com/${{ github.repository }}
git fetch upstream main
git diff --name-only upstream/main...HEAD | grep '/lab/' > ../paths.txt || true
cd ..
# In a real GitHub PR workflow, checkout action checks out the merge commit by default
# We need to switch to the actual PR head to get the correct diff
echo "Current commit: $(git rev-parse HEAD)"
echo "PR head SHA: ${{ github.event.pull_request.head.sha }}"

# Switch to PR head for accurate diff calculation
git checkout ${{ github.event.pull_request.head.sha }} 2>/dev/null || echo "Using current checkout (local testing)"

# For local testing, check if upstream remote already exists, otherwise try to add it
if ! git remote get-url upstream >/dev/null 2>&1; then
# Check if we can add the upstream remote (for real GitHub workflows)
URL="https://github.com/${{ github.event.pull_request.base.repo.full_name }}/archive/refs/heads/${{ github.event.pull_request.base.ref }}.tar.gz"
HTTP_STATUS_LINE=$(curl -s --head "$URL" | head -n 1)
if echo "$HTTP_STATUS_LINE" | grep -q "200 OK"; then
git remote add upstream https://github.com/${{ github.event.pull_request.base.repo.full_name }}.git
git fetch --no-tags --depth=1 upstream ${{ github.event.pull_request.base.ref }}
BASE_REF="upstream/${{ github.event.pull_request.base.ref }}"
else
# For local testing, use local main branch as base
echo "Using local ${{ github.event.pull_request.base.ref }} branch for comparison (local testing mode)"
BASE_REF="${{ github.event.pull_request.base.ref }}"
fi
else
git fetch --no-tags --depth=1 upstream ${{ github.event.pull_request.base.ref }}
BASE_REF="upstream/${{ github.event.pull_request.base.ref }}"
fi

# diff between the base and PR head
git diff --name-only $BASE_REF...HEAD | grep '/lab/' > paths.txt || true
echo ""
echo "Changed files:"
cat paths.txt
mkdir output
mkdir -p output
mv paths.txt output/

- name: Test changed Lab pages
Expand All @@ -56,7 +66,12 @@ jobs:
run: |
if [ -s output/paths.txt ]; then
echo "Changed files found"
python3 base/sources/bin/labs_test.py output/paths.txt
if [ -f "sources/bin/labs_test.py" ]; then
python3 sources/bin/labs_test.py output/paths.txt
else
echo "labs_test.py not found - skipping lab tests (this is expected for testing)"
exit 0
fi
else
echo "No changes to Galaxy Labs found"
fi
Expand Down
Loading