Skip to content

Commit 4099bec

Browse files
usersyrosh
authored andcommitted
test(quickscope): add integration test
1 parent 8c09518 commit 4099bec

File tree

8 files changed

+165
-4
lines changed

8 files changed

+165
-4
lines changed

.github/workflows/pull-request.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Pull Request
2+
3+
on:
4+
pull_request:
5+
6+
permissions:
7+
contents: read
8+
pull-requests: write
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
quickscope:
16+
name: Quickscope
17+
runs-on: ubuntu-latest
18+
outputs:
19+
result: ${{ steps.test.outputs.result }}
20+
steps:
21+
- name: Checkout Repo
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
submodules: true
26+
27+
- name: Build quickscope
28+
working-directory: quickscope
29+
run: docker build -t quickscope .
30+
31+
- name: Run integration test
32+
id: test
33+
working-directory: quickscope
34+
run: |
35+
result=$(./integration/integration.sh | tee /dev/stderr | tail -n1)
36+
echo "result=$result" >> $GITHUB_OUTPUT
37+
38+
- name: Upload diffs
39+
if: ${{ steps.test.outputs.result == 'true' }}
40+
uses: actions/upload-artifact@v4
41+
with:
42+
name: quickscope-diffs
43+
path: |
44+
./quickscope/integration/current.diff
45+
./quickscope/integration/new.diff
46+
./quickscope/integration/integration.diff
47+
48+
comment:
49+
name: Comment integration
50+
needs: quickscope
51+
runs-on: ubuntu-latest
52+
steps:
53+
- name: Checkout Repo
54+
uses: actions/checkout@v4
55+
56+
- name: Post comment
57+
env:
58+
PR_C_REPO: ${{ github.repository }}
59+
PR_C_NUMBER: ${{ github.event.pull_request.number }}
60+
PR_C_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
PR_QS_DIFF: ${{ needs.quickscope.outputs.result }}
62+
run: .internal/ci/comment-integration.sh

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
KEYS
22
env
33
.env
4-
*.swp
4+
*.swp
5+
new.diff
6+
integration.diff

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "lib/pentext"]
2+
path = lib/pentext
3+
url = https://github.com/radicallyopensecurity/pentext.git
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
artifacts_url="https://api.github.com/repos/$PR_C_REPO/actions/runs/$GITHUB_RUN_ID/artifacts"
6+
artifacts_json=$(curl -s -H "Authorization: token $PR_C_TOKEN" "$artifacts_url")
7+
8+
diffs_id=$(echo "$artifacts_json" | jq -r '.artifacts[] | select(.name=="quickscope-diffs") | .id')
9+
diffs_url="https://github.com/$PR_C_REPO/actions/runs/$GITHUB_RUN_ID/artifacts/$diffs_id"
10+
11+
if [ "$PR_QS_DIFF" = "true" ]; then
12+
body="**Quickscope:** Found diff. Please check the diffs: [download]($diffs_url)"
13+
else
14+
body="**Quickscope:** No diff found."
15+
fi
16+
17+
curl -s -H "Authorization: token $PR_C_TOKEN" \
18+
-H "Content-Type: application/json" \
19+
-d "$(jq -nc --arg body "$body" '{body: $body}')" \
20+
"https://api.github.com/repos/$PR_C_REPO/issues/$PR_C_NUMBER/comments"

lib/pentext

Submodule pentext added at 937354f

quickscope/integration/current.diff

Whitespace-only changes.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
GIT_USER=CI
5+
GIT_PASS=dummy
6+
REPO_NAME=test-remote.git
7+
8+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
9+
10+
TMPDIR="$SCRIPT_DIR/tmp"
11+
REMOTE="$TMPDIR/remote"
12+
SOURCE="$TMPDIR/source"
13+
14+
echo "* Preparing tmp dirs"
15+
rm -rf "$TMPDIR"
16+
mkdir -p "$REMOTE" "$SOURCE"
17+
18+
echo "* Cloning test repo into remote"
19+
git -C "$SCRIPT_DIR/../../lib/pentext" \
20+
clone . "$REMOTE/$REPO_NAME"
21+
22+
git -C "$REMOTE/$REPO_NAME" config http.receivepack true
23+
24+
echo "* Starting git-http-backend container"
25+
docker rm -f git-http-backend 2>/dev/null || true
26+
27+
docker run -d --name git-http-backend \
28+
-v "$REMOTE":/git \
29+
ynohat/git-http-backend@sha256:b6f1e3e3cc06b8ae05fc22174808dfc3b4abd567cf8bc8c8bac311d83361b041
30+
31+
echo "* Running quickscope"
32+
docker run --rm --name quickscope \
33+
--link git-http-backend \
34+
-e GIT_SSL_NO_VERIFY=true \
35+
-e SERVER_PROTOCOL=http \
36+
-e CI_PROJECT_DIR=/usr/local/src/repo \
37+
-e CI_SERVER_HOST=git-http-backend \
38+
-e CI_PROJECT_PATH=git/$REPO_NAME \
39+
-e CI_DEFAULT_BRANCH=main \
40+
-e PROJECT_ACCESS_TOKEN=$GIT_PASS \
41+
-v "$REMOTE/$REPO_NAME":/usr/local/src/repo \
42+
--entrypoint ash \
43+
quickscope:latest \
44+
-c "git config --global http.receivepack true && git config --global --add safe.directory /usr/local/src/repo && exec /scripts/quickscope2off.sh"
45+
46+
echo "* Preparing for diff"
47+
git -C "$SCRIPT_DIR/../../lib/pentext" \
48+
clone . "$SOURCE/$REPO_NAME"
49+
docker exec -u 0 git-http-backend rm -rf "/git/$REPO_NAME/.git"
50+
rm -rf "$SOURCE/$REPO_NAME/.git"
51+
52+
echo "* Creating new diff"
53+
diff -ruN "$SOURCE/$REPO_NAME" "$REMOTE/$REPO_NAME" \
54+
| sed -E 's/^(---|\+\+\+) ([^[:space:]]+).*/\1 \2/' \
55+
> "$SCRIPT_DIR/new.diff"
56+
57+
echo "* Diffing with current"
58+
diff -u \
59+
<(sed -E 's/date="[^"]+"/date="IGNORED"/' "$SCRIPT_DIR/current.diff" || true) \
60+
<(sed -E 's/date="[^"]+"/date="IGNORED"/' "$SCRIPT_DIR/new.diff" || true) \
61+
> "$SCRIPT_DIR/integration.diff" || test $? -eq 1
62+
63+
echo "* Cleaning up"
64+
docker rm -f git-http-backend || true
65+
rm -rf "$TMPDIR"
66+
67+
echo "* Found diff?"
68+
if [ -s "$SCRIPT_DIR/integration.diff" ]; then
69+
echo "true"
70+
else
71+
echo "false"
72+
fi

quickscope/scripts/quickscope2off.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#!/bin/sh
1+
#!/usr/bin/env ash
2+
23
set -e
34
cd "$CI_PROJECT_DIR"
45

@@ -11,6 +12,6 @@ git commit -m "convert pentext quickscope to offerte"
1112
git remote -v
1213

1314
git remote rm origin
14-
git remote add origin "https://CI:${PROJECT_ACCESS_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}"
15+
git remote add origin "${SERVER_PROTOCOL:-https}://CI:${PROJECT_ACCESS_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}"
1516

16-
git push origin HEAD:${CI_DEFAULT_BRANCH}
17+
git push origin HEAD:refs/heads/${CI_DEFAULT_BRANCH}

0 commit comments

Comments
 (0)