Fix layout #4
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
# SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and CLA-assistant contributors | |
# | |
# SPDX-License-Identifier: Apache-2.0 | |
name: CI/CDPipeline | |
permissions: | |
id-token: write | |
contents: read | |
on: | |
workflow_dispatch: | |
inputs: | |
ref: | |
description: "commit sha to deploy to staging" | |
required: true | |
default: "refs/heads/main" | |
push: | |
branches: | |
- "*" | |
tags: | |
- "*" | |
pull_request: | |
branches: | |
- main | |
jobs: | |
build: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
node_version: | |
- 16 | |
os: | |
- ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
ref: ${{ github.event.inputs.ref }} | |
- name: Use specified node version | |
uses: actions/setup-node@v1 | |
with: | |
version: ${{ matrix.node_version }} | |
- name: Npm Install | |
run: | | |
npm install | |
- name: grunt build and test | |
run: | | |
grunt build | |
grunt test | |
grunt coverage | |
- name: Test Coverage | |
uses: coverallsapp/github-action@master | |
with: | |
github-token: ${{ secrets.github_token }} | |
git-commit: ${{ github.event.inputs.ref || github.sha }} | |
path-to-lcov: ./output/coverage/lcov.info | |
- name: build the docker image with commit SHA for staging | |
if: ${{ github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' }} | |
run: docker build -t eu.gcr.io/sap-cla-assistant/cla-assistant:${{ github.event.inputs.ref || github.sha }} . | |
- name: build the docker images with tag name and latest for production | |
if: startsWith(github.ref, 'refs/tags') | |
run: docker build -t eu.gcr.io/sap-cla-assistant/cla-assistant:${GITHUB_REF:10} -t eu.gcr.io/sap-cla-assistant/cla-assistant:latest -t sapclaassistant/claassistant:latest -t sapclaassistant/claassistant:${GITHUB_REF:10} . | |
- name: push the latest and release images to dockerhub only for releases | |
if: startsWith(github.ref, 'refs/tags') | |
run: | | |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
docker push sapclaassistant/claassistant | |
- id: "gcp-identity-federation-auth" | |
name: "Authenticate to GCP via OIDC Identity Federation" | |
uses: "google-github-actions/auth@v0.4.4" | |
if: ${{ startsWith(github.ref, 'refs/tags') || github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' }} | |
with: | |
create_credentials_file: "true" | |
workload_identity_provider: "projects/209238640650/locations/global/workloadIdentityPools/github-actions/providers/github-oidc" | |
service_account: "github-actions-containerupload@sap-cla-assistant.iam.gserviceaccount.com" | |
# Configure docker to use the gcloud command-line tool as a credential helper | |
- run: gcloud auth configure-docker | |
if: ${{ startsWith(github.ref, 'refs/tags') || github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' }} | |
- name: push image to gcp during push on main branch for testing in staging | |
if: ${{ github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' }} | |
run: docker push eu.gcr.io/sap-cla-assistant/cla-assistant:${{ github.event.inputs.ref || github.sha }} | |
- name: push images to gcp during new release for production usage | |
if: startsWith(github.ref, 'refs/tags') | |
run: | | |
docker push eu.gcr.io/sap-cla-assistant/cla-assistant:latest | |
docker push eu.gcr.io/sap-cla-assistant/cla-assistant:${GITHUB_REF:10} | |
- name: deploy to staging cloud run service | |
if: ${{ github.ref == 'refs/heads/main' || github.event_name == 'workflow_dispatch' }} | |
run: gcloud --quiet --project sap-cla-assistant beta run deploy cla-assistant-staging --platform managed --region europe-west1 --image eu.gcr.io/sap-cla-assistant/cla-assistant:${{ github.event.inputs.ref || github.sha }} |