Update ci.yml (#53) #88
Workflow file for this run
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 | |
# This job will only be triggered when a PR is merged to `pingcap/provider-aws` branch | |
# or a tag is pushed. | |
on: | |
push: | |
branches: | |
- pingcap/provider-aws | |
tags: | |
- "*" | |
# Uncomment below lines to debug this action in PR | |
# pull_request: | |
# branches: | |
# - pingcap/provider-aws | |
env: | |
GO_VERSION: '1.21' | |
GCR_REG: gcr.io/pingcap-public/crossplane | |
PROJECT_ID: pingcap-public | |
IMAGE_NAME: provider-aws | |
# set the commit id as default value | |
IMAGE_TAG: ${{ github.sha }} | |
jobs: | |
push-the-image: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Go | |
uses: actions/setup-go@v3 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
- name: Find the Go Build Cache | |
id: go | |
run: echo "cache=$(make go.cachedir)" >> $GITHUB_OUTPUT | |
- name: Cache the Go Build Cache | |
uses: actions/cache@v4 | |
with: | |
path: ${{ steps.go.outputs.cache }} | |
key: ${{ runner.os }}-build-publish-artifacts-${{ hashFiles('**/go.sum') }} | |
restore-keys: ${{ runner.os }}-build-publish-artifacts- | |
- name: Cache Go Dependencies | |
uses: actions/cache@v4 | |
with: | |
path: .work/pkg | |
key: ${{ runner.os }}-pkg-${{ hashFiles('**/go.sum') }} | |
restore-keys: ${{ runner.os }}-pkg- | |
- name: Build the binary | |
working-directory: ./ | |
run: CGO_ENABLED=0 GOOS=linux go build -o docker/crossplane-aws-provider cmd/provider/main.go | |
- id: auth | |
uses: google-github-actions/auth@v2 | |
with: | |
credentials_json: ${{ secrets.PUB_GCR_SA_KEY }} | |
- name: Set up Cloud SDK | |
uses: google-github-actions/setup-gcloud@v2 | |
with: | |
project_id: ${{ env.PROJECT_ID }} | |
- name: Test gcloud CLI | |
run: gcloud auth list | |
- name: Configure docker to use the gcloud command-line tool as a credential helper | |
run: | | |
gcloud auth configure-docker gcr.io --quiet | |
- name: Get tag name if any | |
uses: olegtarasov/[email protected] | |
id: tagName | |
- name: Update the image tag, use the tag name as the image tag | |
if: steps.tagName.outputs.tag != '' | |
run: | | |
echo "IMAGE_TAG=${{ steps.tagName.outputs.tag }}" >> $GITHUB_ENV | |
- name: Build docker image | |
run: |- | |
echo "${{ env.IMAGE_TAG }}" | |
cd docker && docker build -t ${{ env.GCR_REG }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} . | |
- name: Push the image to GCR | |
run: | | |
docker push ${{ env.GCR_REG }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} |