mirror of
https://github.com/element-hq/element-desktop.git
synced 2025-12-05 01:10:21 +00:00
Add branch matching (#2329)
This commit is contained in:
committed by
GitHub
parent
85556ecd74
commit
28e558162a
1
.github/workflows/build_and_test.yaml
vendored
1
.github/workflows/build_and_test.yaml
vendored
@@ -15,6 +15,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
config: ${{ (github.event.pull_request.base.ref || github.ref_name) == 'develop' && 'element.io/nightly' || 'element.io/release' }}
|
config: ${{ (github.event.pull_request.base.ref || github.ref_name) == 'develop' && 'element.io/nightly' || 'element.io/release' }}
|
||||||
version: ${{ (github.event.pull_request.base.ref || github.ref_name) == 'develop' && 'develop' || '' }}
|
version: ${{ (github.event.pull_request.base.ref || github.ref_name) == 'develop' && 'develop' || '' }}
|
||||||
|
branch-matching: true
|
||||||
|
|
||||||
windows:
|
windows:
|
||||||
needs: fetch
|
needs: fetch
|
||||||
|
|||||||
25
.github/workflows/build_prepare.yaml
vendored
25
.github/workflows/build_prepare.yaml
vendored
@@ -20,6 +20,11 @@ on:
|
|||||||
required: false
|
required: false
|
||||||
default: false
|
default: false
|
||||||
description: "Whether the build should be deployed to production"
|
description: "Whether the build should be deployed to production"
|
||||||
|
branch-matching:
|
||||||
|
type: boolean
|
||||||
|
required: false
|
||||||
|
default: false
|
||||||
|
description: "Whether the branch name should be matched to find the element-web commit"
|
||||||
secrets:
|
secrets:
|
||||||
# Required if `nightly` is set
|
# Required if `nightly` is set
|
||||||
CF_R2_ACCESS_KEY_ID:
|
CF_R2_ACCESS_KEY_ID:
|
||||||
@@ -59,7 +64,25 @@ jobs:
|
|||||||
- name: Install Deps
|
- name: Install Deps
|
||||||
run: "yarn install --frozen-lockfile"
|
run: "yarn install --frozen-lockfile"
|
||||||
|
|
||||||
- name: Fetch Element Web
|
- name: Fetch Element Web (matching branch)
|
||||||
|
id: branch-matching
|
||||||
|
if: inputs.branch-matching
|
||||||
|
continue-on-error: true
|
||||||
|
run: |
|
||||||
|
scripts/branch-match.sh
|
||||||
|
cp "$CONFIG_DIR/config.json" element-web/
|
||||||
|
yarn --cwd element-web install --frozen-lockfile
|
||||||
|
yarn --cwd element-web run build
|
||||||
|
mv element-web/webapp .
|
||||||
|
yarn asar-webapp
|
||||||
|
env:
|
||||||
|
# These must be set for branch-match.sh to get the right branch
|
||||||
|
REPOSITORY: ${{ github.repository }}
|
||||||
|
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||||
|
CONFIG_DIR: ${{ inputs.config }}
|
||||||
|
|
||||||
|
- name: Fetch Element Web (${{ inputs.version }})
|
||||||
|
if: steps.branch-matching.outcome == 'failure' || steps.branch-matching.outcome == 'skipped'
|
||||||
run: yarn run fetch --noverify -d ${{ inputs.config }} ${{ inputs.version }}
|
run: yarn run fetch --noverify -d ${{ inputs.config }} ${{ inputs.version }}
|
||||||
|
|
||||||
# We split this out to save the build_* scripts having to do it to make use of `hashFiles` in the cache action
|
# We split this out to save the build_* scripts having to do it to make use of `hashFiles` in the cache action
|
||||||
|
|||||||
48
scripts/branch-match.sh
Executable file
48
scripts/branch-match.sh
Executable file
@@ -0,0 +1,48 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Script for downloading a branch of element-web matching the branch a PR is contributed from
|
||||||
|
|
||||||
|
set -x
|
||||||
|
|
||||||
|
deforg="element-hq"
|
||||||
|
defrepo="element-web"
|
||||||
|
|
||||||
|
# The PR_NUMBER variable must be set explicitly.
|
||||||
|
default_org_repo=${GITHUB_REPOSITORY:-"$deforg/$defrepo"}
|
||||||
|
PR_ORG=${PR_ORG:-${default_org_repo%%/*}}
|
||||||
|
PR_REPO=${PR_REPO:-${default_org_repo##*/}}
|
||||||
|
|
||||||
|
# A function that clones a branch of a repo based on the org, repo and branch
|
||||||
|
clone() {
|
||||||
|
org=$1
|
||||||
|
repo=$2
|
||||||
|
branch=$3
|
||||||
|
if [ -n "$branch" ]
|
||||||
|
then
|
||||||
|
echo "Trying to use $org/$repo#$branch"
|
||||||
|
# Disable auth prompts: https://serverfault.com/a/665959
|
||||||
|
GIT_TERMINAL_PROMPT=0 git clone https://github.com/$org/$repo.git $repo --branch "$branch" --depth 1 && exit 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
echo "Getting info about a PR with number $PR_NUMBER"
|
||||||
|
apiEndpoint="https://api.github.com/repos/$PR_ORG/$PR_REPO/pulls/$PR_NUMBER"
|
||||||
|
head=$(curl "$apiEndpoint" | jq -r '.head.label')
|
||||||
|
|
||||||
|
# for forks, $head will be in the format "fork:branch", so we split it by ":"
|
||||||
|
# into an array. On non-forks, this has the effect of splitting into a single
|
||||||
|
# element array given ":" shouldn't appear in the head - it'll just be the
|
||||||
|
# branch name. Based on the results, we clone.
|
||||||
|
BRANCH_ARRAY=(${head//:/ })
|
||||||
|
TRY_ORG=$deforg
|
||||||
|
TRY_BRANCH=${BRANCH_ARRAY[0]}
|
||||||
|
if [[ "$head" == *":"* ]]; then
|
||||||
|
# ... but only match that fork if it's a real fork
|
||||||
|
if [ "${BRANCH_ARRAY[0]}" != "$PR_ORG" ]; then
|
||||||
|
TRY_ORG=${BRANCH_ARRAY[0]}
|
||||||
|
fi
|
||||||
|
TRY_BRANCH=${BRANCH_ARRAY[1]}
|
||||||
|
fi
|
||||||
|
clone "$TRY_ORG" "$defrepo" "$TRY_BRANCH"
|
||||||
|
|
||||||
|
exit 1
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -x
|
|
||||||
|
|
||||||
deforg="$1"
|
|
||||||
defrepo="$2"
|
|
||||||
defbranch="$3"
|
|
||||||
|
|
||||||
[ -z "$defbranch" ] && defbranch="develop"
|
|
||||||
|
|
||||||
rm -r "$defrepo" || true
|
|
||||||
|
|
||||||
clone() {
|
|
||||||
org=$1
|
|
||||||
repo=$2
|
|
||||||
branch=$3
|
|
||||||
if [ -n "$branch" ]
|
|
||||||
then
|
|
||||||
echo "Trying to use $org/$repo#$branch"
|
|
||||||
# Disable auth prompts: https://serverfault.com/a/665959
|
|
||||||
GIT_TERMINAL_PROMPT=0 git clone https://github.com/$org/$repo.git $repo --branch "$branch" --depth 1 && exit 0
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Try the PR author's branch in case it exists on the deps as well.
|
|
||||||
# If BUILDKITE_BRANCH is set, it will contain either:
|
|
||||||
# * "branch" when the author's branch and target branch are in the same repo
|
|
||||||
# * "author:branch" when the author's branch is in their fork
|
|
||||||
# We can split on `:` into an array to check.
|
|
||||||
BUILDKITE_BRANCH_ARRAY=(${BUILDKITE_BRANCH//:/ })
|
|
||||||
if [[ "${#BUILDKITE_BRANCH_ARRAY[@]}" == "1" ]]; then
|
|
||||||
clone $deforg $defrepo $BUILDKITE_BRANCH
|
|
||||||
elif [[ "${#BUILDKITE_BRANCH_ARRAY[@]}" == "2" ]]; then
|
|
||||||
clone ${BUILDKITE_BRANCH_ARRAY[0]} $defrepo ${BUILDKITE_BRANCH_ARRAY[1]}
|
|
||||||
fi
|
|
||||||
# Try the target branch of the push or PR.
|
|
||||||
clone $deforg $defrepo $BUILDKITE_PULL_REQUEST_BASE_BRANCH
|
|
||||||
# Try the current branch from Jenkins.
|
|
||||||
clone $deforg $defrepo `"echo $GIT_BRANCH" | sed -e 's/^origin\///'`
|
|
||||||
# Use the default branch as the last resort.
|
|
||||||
clone $deforg $defrepo $defbranch
|
|
||||||
Reference in New Issue
Block a user