name: Test integration in latest daily # Note: this workflow is triggered via workflow_run, which runs in the context of the default branch. # Therefore we use the statuses api to place it on the source commit manually on: workflow_run: workflows: ["Build and test"] types: [completed] permissions: actions: read contents: read statuses: write # Key on the triggering build's head_sha so each PR head is isolated, and a # repaired rerun (same run_id, same head_sha, new attempt) cancels the now-stale # in-flight run for that head instead of racing it to post a status. concurrency: group: ${{ github.workflow }}-${{ github.event.workflow_run.head_sha }} cancel-in-progress: true env: STATUS_CONTEXT: "Test in latest daily" jobs: get-pr-url: runs-on: ubuntu-latest # Run on ANY pull_request build completion. We branch on conclusion below; if: github.event.workflow_run.event == 'pull_request' outputs: pr_url: ${{ steps.lookup.outputs.url }} conclusion: ${{ github.event.workflow_run.conclusion }} steps: - name: Look up PR url id: lookup env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | PR_URL=$(gh api \ "repos/${{ github.repository }}/commits/${{ github.event.workflow_run.head_sha }}/pulls" \ --jq '.[0].html_url') echo "url=$PR_URL" >> "$GITHUB_OUTPUT" # Pending only on the path where the real test is about to run. - name: Mark status pending on PR commit if: github.event.workflow_run.conclusion == 'success' env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | gh api -X POST \ "repos/${{ github.repository }}/statuses/${{ github.event.workflow_run.head_sha }}" \ -f state="pending" \ -f context="$STATUS_CONTEXT" \ -f description="Running integration test in latest daily…" \ -f target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" full-pack-test: needs: get-pr-url # Real test work runs ONLY on a successful build. if: needs.get-pr-url.outputs.conclusion == 'success' name: Test in latest daily runs-on: ubuntu-latest container: image: ghcr.io/malteeez/gtnh-daily:latest env: PR_URL: ${{ needs.get-pr-url.outputs.pr_url }} steps: - name: Install libc so we can run our binary on alpine run: apk add --no-cache libstdc++ libgcc - name: Check out PR build artifact uses: MalTeeez/packscripts@1.4.12 env: NO_COLOR: 1 with: command: >- pr apply $PR_URL --build_job "Build and test" --artifact_name "build-libs" --other_allowed_owner "GTNewHorizons" --pack_variant "server" github_token: ${{ secrets.GITHUB_TOKEN }} working_directory: /home/gtnh musl: true - name: Run pack test timeout-minutes: 30 run: bash /entrypoint.sh report: needs: [get-pr-url, full-pack-test] # Always run so we can post a terminal status on every concluded build, # including the failed path where full-pack-test was skipped. if: always() && needs.get-pr-url.result == 'success' runs-on: ubuntu-latest steps: # Backstop for the cancel-in-progress race on a repaired rerun. Attempt 1 and # attempt 2 of the triggering build share one run_id but differ in run_attempt, # and both target the SAME commit's status slot. If this run is processing an # earlier attempt than the build's current one, it's stale — bail so a late # attempt-1 result can't clobber the attempt-2 result on the context. - name: Bail if a newer attempt of the triggering build exists id: stalecheck env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | TRIGGER_RUN_ID="${{ github.event.workflow_run.id }}" MY_ATTEMPT="${{ github.event.workflow_run.run_attempt }}" LATEST_ATTEMPT=$(gh api \ "repos/${{ github.repository }}/actions/runs/${TRIGGER_RUN_ID}" \ --jq '.run_attempt' 2>/dev/null || true) echo "::notice::trigger run ${TRIGGER_RUN_ID} — mine=${MY_ATTEMPT} latest=${LATEST_ATTEMPT}" if [ -z "$LATEST_ATTEMPT" ]; then # Couldn't read the triggering run — fail open, let the post proceed. echo "stale=false" >> "$GITHUB_OUTPUT" elif [ "$MY_ATTEMPT" -lt "$LATEST_ATTEMPT" ]; then echo "::notice::Attempt ${MY_ATTEMPT} superseded by attempt ${LATEST_ATTEMPT}; not posting status." echo "stale=true" >> "$GITHUB_OUTPUT" else echo "stale=false" >> "$GITHUB_OUTPUT" fi - name: Report final status to PR commit if: steps.stalecheck.outputs.stale == 'false' env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | CONCL="${{ needs.get-pr-url.outputs.conclusion }}" if [ "$CONCL" != "success" ]; then STATE="failure" DESC="Build failed; integration test not run" else STATE="${{ needs.full-pack-test.result == 'success' && 'success' || 'failure' }}" DESC="Integration test complete" fi gh api -X POST \ "repos/${{ github.repository }}/statuses/${{ github.event.workflow_run.head_sha }}" \ -f state="$STATE" \ -f context="$STATUS_CONTEXT" \ -f description="$DESC" \ -f target_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"