Add go build caching #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
jobs: | |
build-n-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Go | |
uses: actions/setup-go@v4 | |
with: | |
go-version: 1.21.x | |
cache: false | |
- name: Get Go cached paths | |
run: | | |
echo "cache=$(go env GOCACHE)" >> $GITHUB_ENV | |
echo "modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV | |
- name: Set up dependencies cache | |
uses: actions/cache@v3 | |
with: | |
path: | | |
${{ env.cache }} | |
key: setup-go-deps-${{ runner.os }}-go-${{ hashFiles('go.sum go.mod') }} | |
- name: Set up intermediate built files cache | |
uses: actions/cache@v3 | |
with: | |
path: | | |
${{ env.modcache }} | |
key: setup-go-build-${{ env.GOOS }}-${{ env.GOARCH }}-${{ runner.os }}-go-${{ hashFiles('**/*.go /tmp/env') }} | |
restore-keys: | | |
setup-go-build-${{ env.GOOS }}-${{ env.GOARCH }} | |
- name: Build Linux binary | |
run: GOOS=linux GOARCH=amd64 go build | |
- name: Build Docker image | |
run: docker build -t ${{ secrets.DOCKER_USERNAME }}/az-appservice . | |
- name: Login to Docker Hub | |
run: docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Docker push | |
run: docker push ${{ secrets.DOCKER_USERNAME }}/az-appservice | |
- name: Login to Azure with Publishing Profile | |
run: | | |
mkdir ~/.azure | |
echo "${{ secrets.AZ_PROFILE }}" > ~/.azure/azure.pubxml | |
- name: Deploy to Azure Web App | |
run: az webapp restart --name akv-demo-go --resource-group akv-demo-1 |