From 2df7196c00856df6b7e25e8ec181e37e8eba28de Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Thu, 10 Jun 2021 08:32:46 -0400 Subject: [PATCH 1/4] Manually pull the complement branch matching the current branch name. --- .github/workflows/tests.yml | 11 ++++++----- changelog.d/10160.misc | 1 + 2 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 changelog.d/10160.misc diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7c2f7d4b1301..f6e880a74e18 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -305,11 +305,12 @@ jobs: with: path: synapse - - name: Run actions/checkout@v2 for complement - uses: actions/checkout@v2 - with: - repository: "matrix-org/complement" - path: complement + # Attempt to check out the same branch of Complement as the PR. If it + # doesn't exist, fallback to master. + - name: Checkout complement + run: | + mkdir -p complement + (wget -O - https://github.com/matrix-org/complement/archive/$GITHUB_HEAD_REF.tar.gz || wget -O - https://github.com/matrix-org/complement/archive/master.tar.gz) | tar -xz --strip-components=1 -C complement # Build initial Synapse image - run: docker build -t matrixdotorg/synapse:latest -f docker/Dockerfile . diff --git a/changelog.d/10160.misc b/changelog.d/10160.misc new file mode 100644 index 000000000000..80f378130f32 --- /dev/null +++ b/changelog.d/10160.misc @@ -0,0 +1 @@ +Fetch the corresponding complement branch when performing CI. From 2541863223f3e93777af5b4ddc251ab8c07ed971 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Thu, 10 Jun 2021 10:26:17 -0400 Subject: [PATCH 2/4] Use GITHUB_REF if GITHUB_HEAD_REF doesn't exist. --- .github/workflows/tests.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f6e880a74e18..d6a37a1ccc48 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -308,9 +308,16 @@ jobs: # Attempt to check out the same branch of Complement as the PR. If it # doesn't exist, fallback to master. - name: Checkout complement + shell: bash run: | + # For pull requests we want to use GITHUB_HEAD_REF (the pull request + # head branch). Otherwise, we use GITHUB_REF (refs/heads/). + BRANCH_NAME="$GITHUB_HEAD_REF" + if [[ -z "$BRANCH_NAME" ]]; then + BRANCH_NAME="${GITHUB_REF#refs/heads/}" + fi mkdir -p complement - (wget -O - https://github.com/matrix-org/complement/archive/$GITHUB_HEAD_REF.tar.gz || wget -O - https://github.com/matrix-org/complement/archive/master.tar.gz) | tar -xz --strip-components=1 -C complement + (wget -O - https://github.com/matrix-org/complement/archive/$BRANCH_NAME.tar.gz || wget -O - https://github.com/matrix-org/complement/archive/master.tar.gz) | tar -xz --strip-components=1 -C complement # Build initial Synapse image - run: docker build -t matrixdotorg/synapse:latest -f docker/Dockerfile . From 5b183049a7cbfb6da075a7306aced364f54c2299 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Thu, 10 Jun 2021 12:56:50 -0400 Subject: [PATCH 3/4] Also attempt to use GITHUB_BASE_REF. --- .github/workflows/tests.yml | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d6a37a1ccc48..a883703206e3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -310,14 +310,24 @@ jobs: - name: Checkout complement shell: bash run: | - # For pull requests we want to use GITHUB_HEAD_REF (the pull request - # head branch). Otherwise, we use GITHUB_REF (refs/heads/). - BRANCH_NAME="$GITHUB_HEAD_REF" - if [[ -z "$BRANCH_NAME" ]]; then - BRANCH_NAME="${GITHUB_REF#refs/heads/}" - fi mkdir -p complement - (wget -O - https://github.com/matrix-org/complement/archive/$BRANCH_NAME.tar.gz || wget -O - https://github.com/matrix-org/complement/archive/master.tar.gz) | tar -xz --strip-components=1 -C complement + # Attempt to use the version of complement which best matches the current + # build. Depending on whether this is a PR or release, etc. we need to + # use different fallbacks. + # + # 1. First check if there's a similarly named branch (GITHUB_HEAD_REF + # for pull requests, otherwise GITHUB_REF). + # 2. Attempt to use the base branch, e.g. when merging into release-vX.Y + # (GITHUB_BASE_REF for pull requests). + # 3. Use the default complement branch ("master"). + for BRANCH_NAME in "$GITHUB_HEAD_REF" "$GITHUB_BASE_REF" "${GITHUB_REF#refs/heads/}" "master"; do + # Skip empty branch names and merge commits. + if [[ -z "$BRANCH_NAME" || $BRANCH_NAME =~ ^refs/pull/.* ]]; then + continue + fi + + (wget -O - https://github.com/matrix-org/complement/archive/$BRANCH_NAME.tar.gz | tar -xz --strip-components=1 -C complement) && break + done # Build initial Synapse image - run: docker build -t matrixdotorg/synapse:latest -f docker/Dockerfile . From 9b761932213a620400f2497031717ff6b88d1b6c Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Thu, 10 Jun 2021 13:23:44 -0400 Subject: [PATCH 4/4] More quotes. --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a883703206e3..bf36ee1cdfff 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -326,7 +326,7 @@ jobs: continue fi - (wget -O - https://github.com/matrix-org/complement/archive/$BRANCH_NAME.tar.gz | tar -xz --strip-components=1 -C complement) && break + (wget -O - "https://github.com/matrix-org/complement/archive/$BRANCH_NAME.tar.gz" | tar -xz --strip-components=1 -C complement) && break done # Build initial Synapse image