Skip to content

Commit

Permalink
fix(ci): correct commit hashes in published autobahn reports (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
mccutchen authored Feb 20, 2025
1 parent 5d28065 commit aa7a462
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -97,15 +104,15 @@ 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

- 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
Expand Down
11 changes: 11 additions & 0 deletions autobahn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"net/url"
"os"
"os/exec"
"os/user"
"path"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -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",
Expand Down
30 changes: 19 additions & 11 deletions ci/build-github-pages
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,32 @@
# 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
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}"
Expand All @@ -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} <<EOF
cat > "${INDEX_PATH}" <<EOF
<!DOCTYPE html>
<html>
Expand Down Expand Up @@ -100,7 +108,7 @@ cat > ${INDEX_PATH} <<EOF
EOF

# List all report directories in reverse chronological order
REPORT_DIRS=($(ls -rd ${REPORTS_ROOT}/*/))
REPORT_DIRS=($(ls -rd "${REPORTS_ROOT}"/*/))
for dir in "${REPORT_DIRS[@]}"; do
if [ -f "${dir}index.html" ]; then
dir_name=$(basename "$dir")
Expand All @@ -110,7 +118,7 @@ for dir in "${REPORT_DIRS[@]}"; do
# Format the timestamp more readably
FORMATTED_DATE=$(date -d "${DIR_TIMESTAMP:0:8} ${DIR_TIMESTAMP:9:2}:${DIR_TIMESTAMP:11:2}:${DIR_TIMESTAMP:13:2}" '+%Y-%m-%d %H:%M:%S')

cat >> ${INDEX_PATH} <<EOF
cat >> "${INDEX_PATH}" <<EOF
<tr>
<td><a href="${dir_name}/">${FORMATTED_DATE}</a></td>
<td><a href="https://github.com/mccutchen/websocket/commit/${DIR_SHA}">${DIR_SHA}</a></td>
Expand All @@ -119,7 +127,7 @@ EOF
fi
done

cat >> ${INDEX_PATH} << 'EOF'
cat >> "${INDEX_PATH}" << 'EOF'
</table>
</section>
</main>
Expand Down

0 comments on commit aa7a462

Please sign in to comment.