biodiversity community automatic resources update #693
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # This workflow can be tested with `act`: sources/bin/tests/test_labs_test.sh | |
| name: Test changed Lab pages | |
| on: | |
| pull_request: | |
| types: [opened, reopened, synchronize] | |
| jobs: | |
| test-changed-labs: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v7 | |
| with: | |
| fetch-depth: 0 # ensure full history for merge-base diff | |
| - name: Set up Python | |
| uses: actions/setup-python@v7 | |
| with: | |
| python-version: '3.13' | |
| - name: Get list of changed files | |
| id: changed-files | |
| run: | | |
| # 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 -p output | |
| mv paths.txt output/ | |
| - name: Test changed Lab pages | |
| id: test-labs | |
| env: | |
| BRANCH_NAME: ${{ github.event.pull_request.head.ref }} | |
| HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }} | |
| run: | | |
| if [ -s output/paths.txt ]; then | |
| echo "Changed files found" | |
| 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 | |
| continue-on-error: true | |
| - name: Write pull request variables to env.sh | |
| env: | |
| PR_NUMBER: ${{ github.event.number }} | |
| BRANCH_NAME: ${{ github.event.pull_request.head.ref }} | |
| HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }} | |
| BASE_REPO: ${{ github.repository }} | |
| run: | | |
| echo "export PR_NUMBER=${PR_NUMBER}" >> output/env.sh | |
| echo "export BASE_REPO=${BASE_REPO}" >> output/env.sh | |
| - name: Upload test result comments artifact | |
| uses: actions/upload-artifact@v7 | |
| with: | |
| name: labs_test_comments | |
| path: output | |
| - name: Check outcome of the previous step | |
| id: check-outcome | |
| run: | | |
| if [ "${{ steps.test-labs.outcome }}" == "failure" ]; then | |
| echo "Test failed" | |
| exit 1 | |
| else | |
| echo "Test passed" | |
| fi |