From 941b804a069e436460b332b718a0e070b94058c7 Mon Sep 17 00:00:00 2001 From: Ashish Amarnath Date: Wed, 27 May 2020 16:34:12 -0700 Subject: [PATCH] setup ci in github actions Signed-off-by: Ashish Amarnath --- .github/workflows/pr.yml | 2 +- .github/workflows/push.yml | 34 ++++++++++++++++++++++++++++++++++ hack/docker-push.sh | 30 ++++++++++++++++++------------ 3 files changed, 53 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/push.yml diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 2c5964175..e94d41499 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -1,5 +1,5 @@ name: Pull Request CI Check -on: [push, pull_request] +on: [pull_request] jobs: build: diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml new file mode 100644 index 000000000..25e06ae93 --- /dev/null +++ b/.github/workflows/push.yml @@ -0,0 +1,34 @@ +name: Push + +on: + push: + branches: [ master ] + tags: + - '*' + +jobs: + + build: + name: Build + runs-on: ubuntu-latest + steps: + + - name: Set up Go 1.14 + uses: actions/setup-go@v2 + with: + go-version: 1.14 + id: go + + - name: Check out code into the Go module directory + uses: actions/checkout@v2 + + - name: Build + run: make local + + - name: Test + run: make test + + - name: Publish container image + run: | + docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASSWORD }} + ./hack/docker-push.sh diff --git a/hack/docker-push.sh b/hack/docker-push.sh index 6096be14f..4001bc369 100755 --- a/hack/docker-push.sh +++ b/hack/docker-push.sh @@ -20,8 +20,8 @@ set +x -if [[ -z "$TRAVIS" ]]; then - echo "This script is intended to be run only on Travis." >&2 +if [[ -z "$CI" ]]; then + echo "This script is intended to be run only on Github Actions." >&2 exit 1 fi @@ -47,37 +47,43 @@ function highest_release() { done } +triggeredBy=$(echo $GITHUB_REF | cut -d / -f 2) +if [[ "$triggeredBy" == "heads" ]]; then + BRANCH=$(echo $GITHUB_REF | cut -d / -f 3) + TAG= +elif [[ "$triggeredBy" == "tags" ]]; then + BRANCH= + TAG=$(echo $GITHUB_REF | cut -d / -f 3) +fi + if [[ "$BRANCH" == "master" ]]; then VERSION="$BRANCH" -elif [[ ! -z "$TRAVIS_TAG" ]]; then - # Tags aren't fetched by Travis on checkout, and we don't need them for master +elif [[ ! -z "$TAG" ]]; then + # Explicitly checkout tags when building from a git tag. + # This is not needed when building from master git fetch --tags # Calculate the latest release if there's a tag. highest_release - VERSION="$TRAVIS_TAG" + VERSION="$TAG" else - # If we're not on master and we're not building a tag, exit early. + echo "We're not on master and we're not building a tag, exit early." exit 0 fi - # Assume we're not tagging `latest` by default, and never on master. TAG_LATEST=false if [[ "$BRANCH" == "master" ]]; then echo "Building master, not tagging latest." -elif [[ "$TRAVIS_TAG" == "$HIGHEST" ]]; then +elif [[ "$TAG" == "$HIGHEST" ]]; then TAG_LATEST=true fi # Debugging info echo "Highest tag found: $HIGHEST" echo "BRANCH: $BRANCH" -echo "TRAVIS_TAG: $TRAVIS_TAG" +echo "TAG: $TAG" echo "TAG_LATEST: $TAG_LATEST" -echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin -unset GIT_HTTP_USER_AGENT - echo "Building and pushing container images." VERSION="$VERSION" TAG_LATEST="$TAG_LATEST" make all-containers all-push all-manifests