-
Notifications
You must be signed in to change notification settings - Fork 255
89 lines (86 loc) · 3.93 KB
/
build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# 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 }}