diff options
author | Azul <azul@riseup.net> | 2021-01-28 06:55:12 +0100 |
---|---|---|
committer | Nora Widdecke <nora@sequoia-pgp.org> | 2021-02-18 17:25:43 +0100 |
commit | 69f3245169067c9b299ec4806e82f87a22cd1e22 (patch) | |
tree | 24d4ef89611925168956adbd8d2adcce160925ff | |
parent | 1d7ef6ebc22bce6dfe0ea95c2f246a4b552ced47 (diff) |
ci: Only test commits once in all_commits.azul/untested-commits
- When a commit has been tested we keep track of it by touching
a file named by the commit sha in tested_commits.
- Before running the tests in all_commits we check if such a file exists.
- We store these files as artifacts and load them before runs on the same branch.
-rwxr-xr-x | .ci/all_commits.sh | 8 | ||||
-rwxr-xr-x | .ci/test_commit.sh | 24 | ||||
-rw-r--r-- | .gitlab-ci.yml | 57 |
3 files changed, 70 insertions, 19 deletions
diff --git a/.ci/all_commits.sh b/.ci/all_commits.sh index b44f48c5..821fbadb 100755 --- a/.ci/all_commits.sh +++ b/.ci/all_commits.sh @@ -14,11 +14,13 @@ git merge-base --is-ancestor HEAD~ origin/main && echo "All commits tested already" && exit 0 +# Copy the current version of the test_commit script +# so we can use it to test all the previous commits: +cp .ci/test_commit.sh . + # Leave out the last commit - it has already been checked. git checkout HEAD~ -git rebase origin/main \ - --exec 'echo ===; echo ===; echo ===; git log -n 1;' \ - --exec 'cargo test -p sequoia-openpgp' && +git rebase origin/main --exec './test_commit.sh' && echo "All commits passed tests" && exit 0 diff --git a/.ci/test_commit.sh b/.ci/test_commit.sh new file mode 100755 index 00000000..dde3b5ca --- /dev/null +++ b/.ci/test_commit.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash + +# Test one commit if it has not been tested yet. +# +# We mark tested commits by touching a file named with the commit hash +# in the tested_commits dir. + +COMMIT_DIR=tested_commits +COMMIT_SHA=$(git rev-list HEAD -1) +COMMIT_FILE=$COMMIT_DIR/$COMMIT_SHA + +mkdir -p $COMMIT_DIR + +echo ===; echo ===; echo ===; +git log -n 1; + +if [ ! -f $COMMIT_FILE ] +then + cargo test -p sequoia-openpgp && \ + echo $CI_JOB_URL >> $COMMIT_FILE +else + echo $COMMIT_SHA has already been tested in this job: + cat $COMMIT_FILE +fi diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 33177c87..a1dff2c4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -49,22 +49,6 @@ bullseye: RUSTFLAGS: -D warnings -A unused-parens after_script: [] -all_commits: - # Test each commit up to main, to facilitate bisecting. - stage: test - image: registry.gitlab.com/sequoia-pgp/build-docker-image/rust-stable-prebuild:latest - needs: ["rust-stable"] - except: - # Do not run for pushes to the pep-engine branch. - - /^pep-engine$/ - script: - - .ci/all_commits.sh - variables: - CARGO_TARGET_DIR: /target - CARGO_HOME: /cargo - RUSTFLAGS: -D warnings -A unused-parens - GIT_STRATEGY: clone - codespell: tags: - linux @@ -84,10 +68,51 @@ rust-stable: image: registry.gitlab.com/sequoia-pgp/build-docker-image/rust-stable-prebuild:latest script: - CARGO_PACKAGES="-p buffered-reader -p sequoia-openpgp -p sequoia-sqv" make test + - mkdir -p tested_commits + # Mark this commit sha as succesfully run, for all_commits. + - echo $CI_JOB_URL >> tested_commits/$CI_COMMIT_SHA variables: CARGO_TARGET_DIR: /target CARGO_HOME: /cargo RUSTFLAGS: -D warnings -A unused-parens + artifacts: + paths: + - tested_commits + expire_in: 1 week + +# Only test commits once in all_commits. +# When a commit has been tested we keep track of it by touching a file named by +# the commit sha in tested_commits. +# Before running the tests we check if such a file exists. +# We store these files as artifacts and load them before runs on the same branch. +all_commits: + # Test each commit up to main, to facilitate bisecting. + stage: test + image: registry.gitlab.com/sequoia-pgp/build-docker-image/rust-stable-prebuild:latest + needs: ["rust-stable"] + except: + # Do not run for pushes to the pep-engine branch. + - /^pep-engine$/ + # We have a strict farst-forward-merge policy, all commits have been tested by + # this job on the source branche anyway. + - master + script: + - echo $ARTIFACTS + - 'curl -sL -o artifacts.zip -H "JOB-TOKEN: $CI_JOB_TOKEN" "$ARTIFACTS"' + - unzip -n artifacts.zip || echo "No previous runs found." + - if [ -d tested_commits ]; then ls tested_commits; fi + - .ci/all_commits.sh + - if [ -d tested_commits ]; then ls tested_commits; fi + variables: + CARGO_TARGET_DIR: /target + CARGO_HOME: /cargo + RUSTFLAGS: -D warnings -A unused-parens + GIT_STRATEGY: clone + ARTIFACTS: "$CI_API_V4_URL/projects/$CI_PROJECT_ID/jobs/artifacts/$CI_COMMIT_BRANCH/download?job=all_commits" + artifacts: + paths: + - tested_commits + expire_in: 1 week windows-gnu: tags: |