From aa7a4621cf9edfda4cf1c0c64548486de5362be2 Mon Sep 17 00:00:00 2001 From: Will McCutchen Date: Thu, 20 Feb 2025 10:16:03 -0500 Subject: [PATCH] fix(ci): correct commit hashes in published autobahn reports (#46) --- .github/workflows/test.yaml | 15 +++++++++++---- autobahn_test.go | 11 +++++++++++ ci/build-github-pages | 30 +++++++++++++++++++----------- 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 1b0b21d..499ecac 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -15,7 +15,8 @@ permissions: contents: read env: - REPORT_DIR: "out/autobahn" + OUT_DIR: "out" + REPORT_DIR: "out/autobahn" # ideally this would reference $OUT_DIR but GH Actions doesn't support that jobs: test: @@ -61,7 +62,13 @@ jobs: uses: actions/checkout@v4 - name: run autobahn tests - run: make testautobahn + run: | + # this will write the report to $REPORT_DIR + make testautobahn + + # claen up unneded structured json report data from autobahn before + # uploading the artifact + find "${OUT_DIR}" -type f -name '*.json' -delete - name: upload autobahn report artifact uses: actions/upload-artifact@v4 @@ -97,7 +104,7 @@ jobs: uses: actions/download-artifact@v4 with: name: autobahn-report - path: latest-report + path: "${{ env.OUT_DIR }}/latest-report" - name: build github pages run: ./ci/build-github-pages @@ -105,7 +112,7 @@ jobs: - name: upload github pages artifact uses: actions/upload-pages-artifact@v3 with: - path: reports + path: "${{ env.OUT_DIR }}/reports" - name: deploy github pages id: deployment diff --git a/autobahn_test.go b/autobahn_test.go index 2829f99..be1b96a 100644 --- a/autobahn_test.go +++ b/autobahn_test.go @@ -31,6 +31,7 @@ import ( "net/url" "os" "os/exec" + "os/user" "path" "path/filepath" "regexp" @@ -127,11 +128,21 @@ func TestAutobahn(t *testing.T) { pullCmd := exec.Command("docker", "pull", autobahnImage) runCmd(t, pullCmd) + localUser, err := user.Current() + assert.NilError(t, err) + testCmd := exec.Command( "docker", "run", "--net=host", "--rm", + // we run the image as the local user to ensure that, on GH Actions CI + // runners, the output generated by autobahn isn't owned by root and + // therefore can be cleaned up by the CI runner. + // + // See the `find ... -delete` command in .github/workflows/test.yml for + // where this happens. + "--user", fmt.Sprintf("%s:%s", localUser.Uid, localUser.Gid), "-v", testDir+":/testdir:rw", autobahnImage, "wstest", "-m", "fuzzingclient", "--spec", "/testdir/autobahn.json", diff --git a/ci/build-github-pages b/ci/build-github-pages index 0adec4f..2711e2b 100755 --- a/ci/build-github-pages +++ b/ci/build-github-pages @@ -6,7 +6,7 @@ # repo, which provides access to the most recent N Autobahn test suite reports. # # It is meant to be run via our GitHub Actions test workflow, but we can use -# reasonable defaults for local testing (see GITHUB_SHA and GITHUB_PAGES_URL +# reasonable defaults for local testing (see COMMIT_SHA and GITHUB_PAGES_URL # below.) set -euo pipefail @@ -14,16 +14,24 @@ set -x # We expect our GitHub Actions CI steps to provide these values, but we can # offer reasonable defaults for local testing. -GITHUB_SHA="${GITHUB_SHA:-$(git rev-parse HEAD)}" +if [ "${GITHUB_EVENT_PATH:-}" != "" ]; then + # on pushes to main, we want to take the .after SHA, which is the commit + # that will arrive in the main branch. On PRs, during testing, we want to + # take the .head SHA. + COMMIT_SHA=$(jq -r '.after // .pull_request.head.sha' "$GITHUB_EVENT_PATH") +else + COMMIT_SHA=$(git rev-parse HEAD) +fi GITHUB_PAGES_URL="${GITHUB_PAGES_URL:-https://mccutchen.github.io/websocket/}" # Figure out timestamp of the newest report -COMMIT_TIMESTAMP=$(git show -s --format=%cd --date=format:'%Y%m%d-%H%M%S' "$GITHUB_SHA") -COMMIT_SHA=${GITHUB_SHA::8} +COMMIT_TIMESTAMP=$(git show -s --format=%cd --date=format:'%Y%m%d-%H%M%S' "$COMMIT_SHA") +COMMIT_SHA_SHORT=${COMMIT_SHA::8} KEEP_REPORTS=10 -REPORTS_ROOT="reports" -REPORT_DIR="${REPORTS_ROOT}/${COMMIT_TIMESTAMP}-${COMMIT_SHA}" +OUT_DIR="${OUT_DIR:-out}" +REPORTS_ROOT="${OUT_DIR}/reports" +REPORT_DIR="${REPORTS_ROOT}/${COMMIT_TIMESTAMP}-${COMMIT_SHA_SHORT}" INDEX_PATH="${REPORTS_ROOT}/index.html" mkdir -p "${REPORTS_ROOT}" @@ -36,10 +44,10 @@ rm -f "${REPORTS_ROOT}"/robots.txt "${REPORTS_ROOT}"/*.html.* # Copy new report downloaded from test artifcats to its location in the reports # site. -cp -r latest-report "$REPORT_DIR" +cp -r "${OUT_DIR}/latest-report" "$REPORT_DIR" # Generate index.html with $KEEP_REPORTS most recent reports -cat > ${INDEX_PATH} < "${INDEX_PATH}" < @@ -100,7 +108,7 @@ cat > ${INDEX_PATH} <> ${INDEX_PATH} <> "${INDEX_PATH}" < ${FORMATTED_DATE} ${DIR_SHA} @@ -119,7 +127,7 @@ EOF fi done -cat >> ${INDEX_PATH} << 'EOF' +cat >> "${INDEX_PATH}" << 'EOF'