Skip to content

Commit

Permalink
ci: move to GitHub actions (#744)
Browse files Browse the repository at this point in the history
With GitHub actions we can have 20 concurrent jobs. And startup is
faster. It's a no-brainer.

With thanks to @mvdan.

Things that don't (easily) translate:

* being able to set environment variables via the GitHub UI. This means
  that RACE_BUILD is now, in effect, useless because it needs to be set
  in a commit. On top of this it's not possible to re-trigger a build
  from the GitHub UI.
* we don't appear to be able to configure notifications in the build
  config. Only a user can configure what notifications they want to
  receive in their github.com/$USERNAME/notifications page, and those
  config knobs are fairly coarse-grained.

We will convert the config to being CUE-based in a later PR.
  • Loading branch information
myitcv committed Jan 30, 2020
1 parent 484c2d1 commit 59ef3d6
Show file tree
Hide file tree
Showing 11 changed files with 180 additions and 152 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Code generated by genconfig. DO NOT EDIT.
on:
push:
branches:
- master
pull_request:
branches:
- '**'
schedule:
- cron: '0 9 * * *'

env:
GO111MODULE: "on"
GOPROXY: "https://proxy.golang.org"
ARTEFACTS: "$HOME/artefacts"
CI: "true"
DOCKER_HUB_USER: "govimci"
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
GH_USER: "myitcv"
GH_TOKEN: ${{ secrets.GH_TOKEN }}
GOVIM_TEST_RACE_SLOWDOWN: "1.5"

name: Go
jobs:
test:
strategy:
matrix:
os: [ubuntu-latest]
go_version: ["go1.12.14", "go1.13.5", "go1.14beta1"]
vim_flavor: ["vim", "gvim"]
vim_version: ["v8.1.1711", "v8.1.2056", "v8.2.0151"]
runs-on: ${{ matrix.os }}
env:
GO_VERSION: ${{ matrix.go_version }}
VIM_FLAVOR: ${{ matrix.vim_flavor }}
VIM_VERSION: ${{ matrix.vim_version }}
steps:
- name: Checkout code
uses: actions/checkout@v1
- name: Build docker image
run: ./_scripts/buildGovimImage.sh
- name: Run Docker, run!
if: success()
run: ./_scripts/runDockerRun.sh
- name: Tidy up
if: failure()
run: ./_scripts/afterFailure.sh
59 changes: 0 additions & 59 deletions .travis.yml

This file was deleted.

7 changes: 2 additions & 5 deletions _scripts/.docker_env_file
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ GH_USER
GH_TOKEN
GOPROXY
VIM_FLAVOR
TRAVIS_BRANCH
TRAVIS_PULL_REQUEST_BRANCH
TRAVIS_PULL_REQUEST_SLUG
TRAVIS_PULL_REQUEST
TRAVIS_EVENT_TYPE
GITHUB_REF
GITHUB_EVENT_NAME
RACE_BUILD
4 changes: 0 additions & 4 deletions _scripts/afterFailure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ then
exit
fi

# The ARTEFACTS variable set by .travis.yml cannot expand
# variables so we do that here
ARTEFACTS=$(echo $ARTEFACTS)

cd $ARTEFACTS

tidyUp .
Expand Down
2 changes: 1 addition & 1 deletion _scripts/buildGovimImage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ fi

cat Dockerfile.user \
| GO_VERSION=$GO_VERSION VIM_FLAVOR=$VIM_FLAVOR VIM_VERSION=$VIM_VERSION envsubst '$GO_VERSION,$VIM_FLAVOR,$VIM_VERSION' \
| docker build -t govim --build-arg USER=$USER --build-arg UID=$UID --build-arg GID=$(id -g $USER) -
| docker build --progress plain -t govim --build-arg USER=$USER --build-arg UID=$UID --build-arg GID=$(id -g $USER) -
24 changes: 21 additions & 3 deletions _scripts/common.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,37 @@ set -euo pipefail

source "${BASH_SOURCE%/*}/gen_maxVersions_genconfig.bash"

if [ "${CI:-}" == "true" ] && [ "${GITHUB_EVENT_NAME:-}" == "pull_request" ]
then
export GITHUB_PR_NUMBER=$(echo ${GITHUB_REF:-} | grep refs/pull | sed -e 's+/+ +g' | awk '{print $3}')
if [ "$GITHUB_PR_NUMBER" == "" ]
then
echo "Failed to get PR number from GITHUB_REF=${GITHUB_REF:-}"
exit 1
fi
fi

# Expand ARTEFACTS as required (in CI we set it to $HOME/artefacts
# which is not expanded becuase that's config-time)
export ARTEFACTS=$(eval echo ${ARTEFACTS:-})

function doBranchCheck {
if [ "${CI:-}" != "true" ]
then
return
fi
# we are on CI
if [ "${TRAVIS_PULL_REQUEST:-}" == "" ] || [[ "$(curl -s -u $GH_USER:$GH_TOKEN https://api.github.com/repos/govim/govim/pulls/$TRAVIS_PULL_REQUEST | jq -r .title)" != \[WIP\]* ]]
if [ "${GITHUB_EVENT_NAME:-}" != "pull_request" ]
then
return
fi
# we are building a pull request
if [[ "$(curl -s -u $GH_USER:$GH_TOKEN https://api.github.com/repos/govim/govim/pulls/$GITHUB_PR_NUMBER | jq -r .title)" != \[WIP\]* ]]
then
return
fi
# We have a WIP pull request
if [ "$(eval "echo \${CI_MUST_RUN_${TRAVIS_PULL_REQUEST}:-}")" == "true" ]
if [ "$(eval "echo \${CI_MUST_RUN_${GITHUB_PR_NUMBER}:-}")" == "true" ]
then
# we must run all builds in the matrix for this PR
return
Expand All @@ -26,4 +45,3 @@ function doBranchCheck {
echo "Skipping build for ${VIM_FLAVOR}_${VIM_VERSION}_${GO_VERSION}"
exit 0
}

23 changes: 12 additions & 11 deletions _scripts/dockerRun.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,24 @@

source "${BASH_SOURCE%/*}/common.bash"

# This ensures that Travis properly runs the after_failure script
# This ensures that GitHub Actions properly runs the after_failure script
trap 'set +ev' EXIT

# We run race builds/tests on Travis CI master branch. We also define that the
# RACE_BUILD environment variable be a comma-separated list of PR numbers (just
# the number, no '#'), and if the CI build in question is a PR build whose
# number is present in RACE_BUILD we also run race builds/tests.
# We run race builds/tests on master branch. We also define that the RACE_BUILD
# environment variable be a comma-separated list of PR numbers (just the
# number, no '#'), and if the CI build in question is a PR build whose number
# is present in RACE_BUILD we also run race builds/tests.
runRace=false
if [[ "${CI:-}" == "true" ]]
then
if [[ "${TRAVIS_BRANCH:-}_${TRAVIS_PULL_REQUEST_BRANCH:-}" == "master_" ]]
if [[ "${GITHUB_REF:-}" == "refs/heads/master" ]]
then
runRace=true
else
elif [[ "${GITHUB_EVENT_NAME:-}" == "pull_request" ]]
then
for i in $(echo ${RACE_BUILD:-} | sed "s/,/ /g")
do
if [[ "${TRAVIS_PULL_REQUEST:-}" == "$i" ]]
if [[ "${GITHUB_PR_NUMBER:-}" == "$i" ]]
then
runRace=true
fi
Expand Down Expand Up @@ -54,7 +55,7 @@ fi
go version
vim --version

if [ "${TRAVIS_EVENT_TYPE:-}" == "cron" ]
if [ "${GITHUB_EVENT_NAME:-}" == "schedule" ]
then
go mod edit -dropreplace=golang.org/x/tools -dropreplace=golang.org/x/tools/gopls
go get golang.org/x/tools/gopls@master golang.org/x/tools@master
Expand All @@ -66,7 +67,7 @@ fi
go install golang.org/x/tools/gopls

# remove all generated files to ensure we are never stale
rm -f $(git ls-files -- ':!:cmd/govim/internal/golang_org_x_tools' '**/gen_*.*' 'gen_*.*') .travis.yml
rm -f $(git ls-files -- ':!:cmd/govim/internal/golang_org_x_tools' '**/gen_*.*' 'gen_*.*')

# Run the install scripts
export GOVIM_RUN_INSTALL_TESTSCRIPTS=true
Expand All @@ -85,7 +86,7 @@ fi
go vet $(go list ./... | grep -v 'govim/internal/golang_org_x_tools')
go run honnef.co/go/tools/cmd/staticcheck $(go list ./... | grep -v 'govim/internal/golang_org_x_tools')

if [ "${CI:-}" == "true" ] && [ "${TRAVIS_EVENT_TYPE:-}" != "cron" ]
if [ "${CI:-}" == "true" ] && [ "${GITHUB_EVENT_NAME:-}" != "schedule" ]
then
go mod tidy
diff <(echo -n) <(go run golang.org/x/tools/cmd/goimports -d $(git ls-files '**/*.go' '*.go' | grep -v golang_org_x_tools))
Expand Down
4 changes: 2 additions & 2 deletions _scripts/rebuildDockerImages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ vbashVersion="$(go list -m -f={{.Version}} github.com/myitcv/vbash)"
for j in $GO_VERSIONS
do
# Build base layer image
docker build --build-arg "GH_USER=$GH_USER" --build-arg "GH_TOKEN=$GH_TOKEN" --build-arg "VBASHVERSION=$vbashVersion" --build-arg "GO_VERSION=${j}" -t govim/govim:base_${j}_${vbashVersion} -f Dockerfile.base .
docker build --progress plain --build-arg "GH_USER=$GH_USER" --build-arg "GH_TOKEN=$GH_TOKEN" --build-arg "VBASHVERSION=$vbashVersion" --build-arg "GO_VERSION=${j}" -t govim/govim:base_${j}_${vbashVersion} -f Dockerfile.base .

for ii in $VALID_FLAVORS
do
for i in $(eval "echo \$${ii^^}_VERSIONS")
do
docker build --build-arg "GH_USER=$GH_USER" --build-arg "GH_TOKEN=$GH_TOKEN" --build-arg "VBASHVERSION=$vbashVersion" --build-arg "GO_VERSION=$j" --build-arg "VIM_VERSION=$i" -t govim/govim:${j}_${ii}_${i}_v1 -f Dockerfile.${ii} . ##
docker build --progress plain --build-arg "GH_USER=$GH_USER" --build-arg "GH_TOKEN=$GH_TOKEN" --build-arg "VBASHVERSION=$vbashVersion" --build-arg "GO_VERSION=$j" --build-arg "VIM_VERSION=$i" -t govim/govim:${j}_${ii}_${i}_v1 -f Dockerfile.${ii} . ##
done
done
done
Expand Down
4 changes: 0 additions & 4 deletions _scripts/runDockerRun.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ doBranchCheck

cd "${BASH_SOURCE%/*}/../"

# The ARTEFACTS variable set by .travis.yml cannot expand
# variables so we do that here
ARTEFACTS=$(echo ${ARTEFACTS:-})

artefacts=""
proxy=""

Expand Down
2 changes: 1 addition & 1 deletion _scripts/tagDockerLatest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ then
fi

# If we are on CI, only tag if we are on the master branch
if [[ "${CI:-}" == "true" ]] && [[ "${TRAVIS_BRANCH:-}_${TRAVIS_PULL_REQUEST_BRANCH:-}" != "master_" ]]
if [[ "${CI:-}" == "true" ]] && [[ "${GITHUB_REF:-}" != "refs/heads/master" ]]
then
echo "Skipping tagging of :latest docker image; we are not building master branch"
exit 0
Expand Down

0 comments on commit 59ef3d6

Please sign in to comment.