Refactor authentication layer. #154
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: | |
push: | |
branches: | |
- master | |
tags: | |
- '**' | |
pull_request: | |
jobs: | |
build: | |
runs-on: [ubuntu-latest] | |
permissions: | |
contents: 'read' | |
id-token: 'write' | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Set tag & repo name for PR builds | |
if: ${{ !contains(fromJson('["refs/heads/master" ]'), github.ref) && !startsWith(github.event.ref, 'refs/tags/v') }} | |
run: | | |
echo "IMAGE_TAG=PR-${{ github.event.number }}" >> $GITHUB_ENV | |
echo "REPO=deepsource-dev" >> $GITHUB_ENV | |
- name: Set tag & repo name for master builds | |
if: contains(fromJson('["refs/heads/master"]'), github.ref) | |
run: | | |
echo "IMAGE_TAG=master" >> $GITHUB_ENV | |
echo "REPO=deepsource-dev" >> $GITHUB_ENV | |
- name: Set tag & repo name for releases | |
if: startsWith(github.event.ref, 'refs/tags/v') | |
run: | | |
echo "IMAGE_TAG=${{ github.ref_name }}" >> $GITHUB_ENV | |
echo "REPO=deepsource-production" >> $GITHUB_ENV | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- id: auth-dev | |
name: Authenticate to Google Cloud Development | |
if: ${{ !startsWith(github.event.ref, 'refs/tags/v') }} | |
uses: "google-github-actions/auth@v1" | |
with: | |
token_format: 'access_token' | |
workload_identity_provider: ${{ secrets.GCP_DEV_WORKLOAD_IDP }} | |
service_account: "${{ secrets.GCP_DEV_SVC_ACCOUNT }}" | |
- name: Docker login GCR Development | |
if: ${{ !startsWith(github.event.ref, 'refs/tags/v') }} | |
uses: 'docker/login-action@v1' | |
with: | |
registry: 'us.gcr.io' | |
username: 'oauth2accesstoken' | |
password: '${{ steps.auth-dev.outputs.access_token }}' | |
- id: auth-prod | |
name: Authenticate to Google Cloud Production | |
if: startsWith(github.event.ref, 'refs/tags/v') | |
uses: "google-github-actions/auth@v1" | |
with: | |
token_format: 'access_token' | |
workload_identity_provider: ${{ secrets.GCP_PROD_WORKLOAD_IDP }} | |
service_account: "${{ secrets.GCP_PROD_SVC_ACCOUNT }}" | |
- name: Docker login GCR Production | |
if: startsWith(github.event.ref, 'refs/tags/v') | |
uses: 'docker/login-action@v1' | |
with: | |
registry: 'us.gcr.io' | |
username: 'oauth2accesstoken' | |
password: '${{ steps.auth-prod.outputs.access_token }}' | |
- name: Build and push | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: true | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
build-args: VERSION=${{ env.IMAGE_TAG }} | |
tags: us.gcr.io/${{ env.REPO }}/runner:${{ env.IMAGE_TAG }} |