Skip to content

Merge pull request #100 from enniosousa/master #137

Merge pull request #100 from enniosousa/master

Merge pull request #100 from enniosousa/master #137

Workflow file for this run

name: CI/CD
on:
push:
pull_request:
env:
IMAGE_NAME: cloud-tasks-emulator
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.13
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Cache dependencies
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Build
run: go build -v .
- name: Test
run: go test -v .
docker-smoke-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME
- name: Cache smoketest dependencies
uses: actions/cache@v2
with:
path: /tmp/smoketest-packages
key: smoketests-pkgs-${{ hashFiles('docker-smoketests/go.*') }}
restore-keys: |
smoketests-pkgs
- name: Run container smoketests
run: EMULATOR_DOCKER_IMAGE=$IMAGE_NAME docker-smoketests/smoketests.sh
docker-publish:
runs-on: ubuntu-latest
needs: [test, docker-smoke-test]
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Publish to Github Packages
run: |
set -o errexit
set -o nounset
# Login to Github registry
# Needs a PAT with `read:packages` and `write:packages` scopes, be *very* careful not to grant `repo` scope
# or anyone with push access on this repo can hijack your GH account!
echo "${{ secrets.GH_CR_IMG_PUSH_PAT }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Push to the remote repo
# This assumes a higher version will always be tagged later
echo "Publishing $IMAGE_ID:$VERSION"
docker buildx build . --platform linux/amd64,linux/arm64 --tag $IMAGE_ID:$VERSION --tag $IMAGE_ID:latest --push