Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Martí <[email protected]>
Change-Id: I7f687dc31010bc0e0005d3385c8388c6657d5362
  • Loading branch information
mvdan committed Nov 1, 2023
1 parent 8c826bc commit d7b1a4d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 78 deletions.
78 changes: 12 additions & 66 deletions .github/workflows/trybot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,78 +110,24 @@ jobs:
github.repository == 'cue-lang/cue' && (((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, '
Dispatch-Trailer: {"type":"')))) || github.ref == 'refs/heads/ci/test')
run: go clean -testcache
- if: (matrix.go-version == '1.21.x' && matrix.runner == 'ubuntu-22.04')
name: Early git and code sanity checks
run: |-
# Ensure the recent commit messages have Signed-off-by headers. We
# only need to check the HEAD commit because all commits are tested
# in CI. Unclear why git log outputs blank lines when parsing trailers
# in this way, but we remove those blank lines so as not to skew the
# count of the trailers we are searching for.
#
# TODO: Remove once this is enforced for admins too;
# see https://bugs.chromium.org/p/gerrit/issues/detail?id=15229
if [[ "$(git log -1 --pretty='%(trailers:key=Signed-off-by)' | sed '/^\s*$/d' | wc -l)" -eq 0 ]]; then
echo -e "\nRecent commit is lacking Signed-off-by:\n"
git show --quiet
exit 1
fi
# Ensure that commit messages have a blank second line.
# We know that a commit message must be longer than a single
# line because each commit must be signed-off.
if git log --format=%B -n 1 HEAD | sed -n '2{/^$/{q1}}'; then
echo "second line of commit message must be blank"
exit 1
fi
# Ensure that the commit author is the same as the signed-off-by. This
# is a basic requirement of DCO. It is enforced by Gerrit (although
# noting that in Gerrit the author name does not have to match, only
# the email address), but _not_ by the DCO GitHub app:
#
# https://github.com/dcoapp/app/issues/201
#
# Provide a sanity check as part of GitHub workflows that should enforce
# this, e.g. trybot workflows.
#
# We do so by comparing the commit author and "Signed-off-by" trailer for
# strict equality. Whilst this is more strict than Gerrit, it should
# generally be the case, and we can always relax this when presented with
# specific situations where it is is a problem.
# commit author email address
commitauthor="$(git log -1 --pretty="%ae")"
# signed-off-by trailer email address. There is no way to parse just the
# email address from the trailer in the same way as git log, so instead
# grab the relevant trailer and then take the last whitespace-delimited
# part as the "<>" contained email address.
# Getting the Signed-off-by trailer in this way causes blank
# lines for some reason. Use awk to remove them.
commitsigner="$(git log -1 --pretty='%(trailers:key=Signed-off-by,valueonly)' | sed -ne 's/.* <\(.*\)>/\1/p')"
if [[ "$commitauthor" != "$commitsigner" ]]; then
echo "commit author email address does not match signed-off-by trailer"
exit 1
fi
- if: |-
((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, '
Dispatch-Trailer: {"type":"')))) || (matrix.go-version == '1.21.x' && matrix.runner == 'ubuntu-22.04')
run: echo CUE_LONG=true >> $GITHUB_ENV
- if: (matrix.go-version == '1.21.x' && matrix.runner == 'ubuntu-22.04')
name: Generate
run: go generate ./...
- if: |-
((github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release-branch.')) && (! (contains(github.event.head_commit.message, '
Dispatch-Trailer: {"type":"')))) || !(matrix.go-version == '1.21.x' && matrix.runner == 'ubuntu-22.04')
name: Test
run: go test ./...
- if: (matrix.go-version == '1.21.x' && matrix.runner == 'ubuntu-22.04')
name: Test with -race
run: go test -race ./...
name: End-to-end test
run: |-
echo ${GITHUB_TOKEN}
echo ${E2E_GITHUB_TOKEN}
if [[ $GITHUB_TOKEN == $E2E_GITHUB_TOKEN ]]; then
echo same
else
echo different
fi
cd internal/e2e
GITHUB_TOKEN=${E2E_GITHUB_TOKEN} go test
env:
GORACE: atexit_sleep_ms=10
E2E_GITHUB_TOKEN: ${{ secrets.E2E_GITHUB_TOKEN }}
- if: (matrix.go-version == '1.21.x' && matrix.runner == 'ubuntu-22.04')
name: Check
run: go vet ./...
Expand Down
46 changes: 34 additions & 12 deletions internal/ci/github/trybot.cue
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,23 @@ workflows: trybot: _repo.bashWorkflow & {
// are established by running each tool.
for v in _setupGoActionsCaches {v},

_repo.earlyChecks & {
// These checks don't vary based on the Go version or OS,
// so we only need to run them on one of the matrix jobs.
if: _isLatestLinux
},
// _repo.earlyChecks & {
// // These checks don't vary based on the Go version or OS,
// // so we only need to run them on one of the matrix jobs.
// if: _isLatestLinux
// },
json.#step & {
if: "\(_repo.isProtectedBranch) || \(_isLatestLinux)"
run: "echo CUE_LONG=true >> $GITHUB_ENV"
},
_goGenerate,
_goTest & {
if: "\(_repo.isProtectedBranch) || !\(_isLatestLinux)"
},
_goTestRace & {
if: _isLatestLinux
},
// _goGenerate,
// _goTest & {
// if: "\(_repo.isProtectedBranch) || !\(_isLatestLinux)"
// },
// _goTestRace & {
// if: _isLatestLinux
// },
_e2eTest,
_goCheck,
_repo.checkGitClean,
]
Expand Down Expand Up @@ -114,6 +115,27 @@ workflows: trybot: _repo.bashWorkflow & {
run: "go test ./..."
}

_e2eTest: json.#step & {
name: "End-to-end test"
// The end-to-end tests require the GITHUB_TOKEN secret and are a bit slow,
// so we only run them on pushes to protected branches and on one environment.
if: "\(_isLatestLinux)"
// Note that Actions runs with a default GITHUB_TOKEN, which we override here.
// env: GITHUB_TOKEN: "${{ secrets.E2E_GITHUB_TOKEN }}"
env: E2E_GITHUB_TOKEN: "${{ secrets.E2E_GITHUB_TOKEN }}"
run: """
echo ${GITHUB_TOKEN}
echo ${E2E_GITHUB_TOKEN}
if [[ $GITHUB_TOKEN == $E2E_GITHUB_TOKEN ]]; then
echo same
else
echo different
fi
cd internal/e2e
GITHUB_TOKEN=${E2E_GITHUB_TOKEN} go test
"""
}

_goCheck: json.#step & {
// These checks can vary between platforms, as different code can be built
// based on GOOS and GOARCH build tags.
Expand Down

0 comments on commit d7b1a4d

Please sign in to comment.