ci: Move from Travis to GitHub Actions (#308)

* Initial commit

* trimpath error

* Test

* test priority

* Another versiong

* ON push only

* Build also

* Enable GO11MODULE

* Disable trimpath

* Separate jobs

* Change stuff

* Matrix build again

* Remove mapping

* Don't use script

* Disable version temp

* Restore

* Deploy on master only

* Deploy on master push

* Remove unused code

* Rename GitHub token secret

The GITHUB_ prefix is reserved (see https://help.github.com/en/articles/virtual-environments-for-github-actions#naming-conventions) and I was not able to create a secret called GITHUB_TOKEN
This commit is contained in:
kiloreux 2019-10-01 16:58:22 +01:00 committed by Marius
parent 6f24143015
commit ee5d881ad3
5 changed files with 58 additions and 109 deletions

58
.github/workflows/main.yml vendored Normal file
View File

@ -0,0 +1,58 @@
on: [push]
name: Test
jobs:
test:
strategy:
matrix:
go-version: [1.12.x, 1.13.x]
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Install Matrix Go
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v1
- name: Test code
env:
GO111MODULE: on
run: |
go test ./pkg/...
go vet ./pkg/...
build:
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
steps:
- name: Install Go 1.13.1
uses: actions/setup-go@v1
with:
go-version: '1.13.1'
- name: Checkout code
uses: actions/checkout@v1
- name: Build TUSD
env:
GO111MODULE: on
run: ./scripts/build_all.sh
- uses: azure/container-actions/docker-login@master
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build and push docker image
run: |
docker build -t tusproject/tusd:$GITHUB_SHA .
docker push tusproject/tusd:$GITHUB_SHA
- name: Deploy to cluster
uses: steebchen/kubectl@master
env:
KUBE_CONFIG_DATA: |
${{ secrets.KUBECONFIG }}
with:
args: set image --record deployment/tusd tusd=tusproject/tusd:$GITHUB_SHA -n tus
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: tusd_*.*
env:
GITHUB_TOKEN: ${{ secrets.GH_RELEASE_TOKEN }}

View File

@ -1,44 +0,0 @@
language: go
go:
- 1.12
- 1.13
env:
- GO111MODULE=on
os:
- linux
- windows
sudo: required
addons:
apt:
packages:
- docker-ce
cache:
apt: true
directories:
- $HOME/.gimme
- "$HOME/google-cloud-sdk/"
install:
- true
script:
- ./scripts/test_all.sh
before_deploy:
- if [[ "$TRAVIS_TAG" != "" ]]; then ./scripts/build_all.sh; fi
deploy:
- provider: releases
api_key:
secure: dV3wr9ebEps3YrzIoqmkYc7fw0IECz7QLPRENPSxTJyd5TTYXGsnTS26cMe2LdGwYrXw0njt2GGovMyBZFTtxyYI3mMO4AZRwvZfx/yGzPWJBbVi6NjZVRg/bpyK+mQJ5BUlkPAYJmRpdc6qD+nvCGakBOxoByC5XDK+yM+bKFs=
file_glob: true
file: tusd_*.*
skip_cleanup: true
on:
tags: true
go: 1.13
repo: tus/tusd
condition: $TRAVIS_OS_NAME = linux
- provider: script
script: scripts/deploy_kube.sh
on:
branch: master
go: 1.13
repo: tus/tusd
condition: $TRAVIS_OS_NAME = linux

View File

@ -1,14 +0,0 @@
clone_folder: c:\projects\go\src\github.com\tus\tusd
environment:
GOPATH: c:\projects\go
GO111MODULE: on
build_script:
- set PATH=%GOPATH%\bin;%PATH%
- go env
- go version
test_script:
- go test ./pkg/...
- go vet ./pkg/...

View File

@ -1,45 +0,0 @@
#!/usr/bin/env bash
set -o pipefail
set -o errexit
set -o nounset
# set -o xtrace
# Set magic variables for current FILE & DIR
__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
__root="$(cd "$(dirname "${__dir}")" && pwd)"
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x ./kubectl
sudo mv ./kubectl /usr/local/bin/kubectl
#Store the new image in docker hub
docker build --quiet -t tusproject/tusd:latest -t tusproject/tusd:$TRAVIS_COMMIT ${__root};
docker login -u "$DOCKER_USERNAME" -p "$DOCKER_PASSWORD";
docker push tusproject/tusd:$TRAVIS_COMMIT;
docker push tusproject/tusd:latest;
echo "Create directory..."
mkdir ${HOME}/.kube
echo "Writing KUBECONFIG to file..."
echo $KUBECONFIGVAR | python -m base64 -d > ${HOME}/.kube/config
echo "KUBECONFIG file written"
sleep 10s # This cost me some precious debugging time.
kubectl apply -f "${__root}/infra/kube/tusd-kube.yaml"
kubectl set image deployment/tusd --namespace=tus tusd=docker.io/tusproject/tusd:$TRAVIS_COMMIT
kubectl get pods --namespace=tus
kubectl get service --namespace=tus
kubectl get deployment --namespace=tus
function cleanup {
printf "Cleaning up...\n"
rm -f ${HOME}/.kube/config
printf "Cleaning done."
}
trap cleanup EXIT

View File

@ -1,6 +0,0 @@
#!/usr/bin/env bash
set -e
go test ./pkg/...
go vet ./pkg/...