Skip to content

Commit

Permalink
Merge pull request #1769 from clash-lang/backport-1705
Browse files Browse the repository at this point in the history
Backport #1705 to 1.4
  • Loading branch information
martijnbastiaan authored Apr 15, 2021
2 parents 19ca0e9 + a2a6c48 commit c9c46f1
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 64 deletions.
52 changes: 52 additions & 0 deletions .ci/kloonbot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash
set -euo pipefail
set -x
IFS=$'\n\t'

HEADERS="Accept: application/vnd.github.v3+json"

kloon_fork_branch_to_local_branch() {
local pull_request_json="$1"
local commit="$2"
local clone_url=$(echo "${pull_request_json}" | jq -r ".head.repo.clone_url")
local author=$(echo "${pull_request_json}" | jq -r ".head.user.login")
local branch_name=$(echo "${pull_request_json}" | jq -r ".head.ref")
local new_branch_name="fork/${author}/${branch_name}"

git remote add fork "${clone_url}"
git fetch fork
git branch -D "${new_branch_name}" || true
git checkout -b "${new_branch_name}"
git reset "$commit" --hard
git push --set-upstream origin "${new_branch_name}" -f
}

parse_comment(){
local line=$(echo "${KBOT_COMMENT}" | head -n 1)
local at=$(echo "${line}" | awk '{print $1}')
local cmd=$(echo "${line}" | awk '{print $2}')
local commit=$(echo "${line}" | awk '{print $3}')

if [[ ${at} == "@kloonbot" && ${cmd} == "run_ci" ]]; then
echo $(echo "$commit" | tr -d '\n\r ')
else
echo "parse_comment: Could not parse comment" 1>&2
exit 1;
fi
}

if [[ $KBOT_AUTHOR_ASSOC =~ ^(OWNER|MEMBER|COLLABORATOR)$ ]]; then
commit=$(parse_comment)

pull_request_json=$(curl -H "${HEADERS}" "${KBOT_PULL_REQUEST_URL}")
is_fork=$(echo "$pull_request_json" | jq -r ".head.repo.fork")

if [[ ${is_fork} == "true" ]]; then
# At this point we've established that:
#
# 1. This pull request is coming from a forked repo
# 2. A comment was made by someone trusted
# 3. The comment indicated CI should be run on local runners
kloon_fork_branch_to_local_branch "${pull_request_json}" "${commit}"
fi
fi
2 changes: 1 addition & 1 deletion .ci/stack_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ apt update
apt install wget -y
wget -q https://get.haskellstack.org/ -O stack_install.sh
sh stack_install.sh
stack build -j${THREADS} --flag clash-prelude:-large-tuples
stack build -j${THREADS}
63 changes: 0 additions & 63 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,6 @@ aliases:
.ci/build.sh
fi
- &nix_setup
run:
name: Setup binaries (such as git)
command: |
# Circle CI needs git/ssh in /usr/bin
nix-env -i git findutils gnugrep gnused coreutils openssh bash-4.4-p23
# bin nix pkg multiple may exist
ln -s $(find /nix -type f -name git | grep libexec | head -n1) /usr/bin
ln -s $(find /nix -type f -name ssh | grep openssh | head -n1) /usr/bin
ln -s $(find /nix -type f -name sed | grep gnused | head -n1) /usr/bin
ln -s $(find /nix -type f -name bash | grep bash-4.4-p23 | head -n1) /bin
- &nix_build
run:
name: Build dependencies and Clash itself with Nix
command: .ci/nix_build.sh
no_output_timeout: 1h

- &stack_build
run:
name: Build dependencies and Clash itself with Stack
command: .ci/stack_build.sh

- &run_tests
run:
name: Run tests
Expand Down Expand Up @@ -131,33 +107,6 @@ aliases:
- *build
- *cache_save
- *run_tests
- &build_with_stack
docker:
- image: docker.pkg.github.com/clash-lang/clash-compiler/clash-ci-$GHC_VERSION:2021-02-08
# Read-only permissions
auth:
username: clash-lang-builder
password: $DOCKER_PASS
steps:
- checkout
- *merge_pullrequest
- *submodules
- *cache_calc_key
- *cache_restore
- *stack_build
- *cache_save
- &build_with_nix
docker:
- image: nixos/nix
steps:
- *cache_calc_key
- *cache_restore
- *nix_setup
- checkout
- *merge_pullrequest
- *submodules
- *nix_build
- *cache_save

workflows:
version: 2
Expand All @@ -168,8 +117,6 @@ workflows:
# - ghc-8.6
- ghc-8.8
- ghc-8.10
- stack-build
- nix-build

jobs:
ghc-8.4:
Expand Down Expand Up @@ -203,13 +150,3 @@ jobs:
CABAL_VERSION: 3.0.0.0
MULTIPLE_HIDDEN: no
<<: *build_default
stack-build:
environment:
GHC_VERSION: 8.10.3
CABAL_VERSION: 3.2.0.0
<<: *env
<<: *build_with_stack
nix-build:
environment:
<<: *env
<<: *build_with_nix
21 changes: 21 additions & 0 deletions .github/workflows/kloonbot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: CI

on: issue_comment

jobs:
kloonbot:
name: Clone branch to local branch
runs-on: ubuntu-latest
if: ${{ github.event.issue.pull_request }}

env:
KBOT_AUTHOR_ASSOC: ${{ github.event.comment.author_association }}
KBOT_COMMENT: ${{ github.event.comment.body }}
KBOT_PULL_REQUEST_URL: ${{ github.event.issue.pull_request.url }}

steps:
- name: Checkout
uses: actions/checkout@v2

- run: |
./.ci/kloonbot.sh
30 changes: 30 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,36 @@ tests-9.0:
GHC_VERSION: 9.0.1
CABAL_VERSION: 3.4.0.0

stack-build:
extends: .common
needs: []
stage: test
variables:
GHC_VERSION: 8.10.3
CABAL_VERSION: 3.2.0.0
script:
- .ci/stack_build.sh
# Run on shared runners
tags:

nix-build:
image: nixos/nix
needs: []
stage: test
before_script:
# Circle CI needs git/ssh in /usr/bin
- nix-env -i git findutils gnugrep gnused coreutils openssh bash-4.4-p23 zstd

# bin nix pkg multiple may exist
- ln -s $(find /nix -type f -name git | grep libexec | head -n1) /usr/bin
- ln -s $(find /nix -type f -name ssh | grep openssh | head -n1) /usr/bin
- ln -s $(find /nix -type f -name sed | grep gnused | head -n1) /usr/bin
- ln -s $(find /nix -type f -name zstd | grep zstd | head -n1) /usr/bin
- ln -s $(find /nix -type f -name bash | grep bash-4.4-p23 | head -n1) /bin

script:
- .ci/nix_build.sh

# Tests run on shared runners:
haddock:
extends: .common
Expand Down

0 comments on commit c9c46f1

Please sign in to comment.