forked from Zied-Belkhiria-Mhp/product-portal-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (73 loc) · 2.57 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
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: build
on:
push:
branches:
- 'dev'
- 'main'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
COMMIT_SHA: ${{ github.sha }}
jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
ref: ${{ github.ref }}
- name: Install Dependencies
run: yarn
- name: Linter Checks
run: yarn lint
- name: Build Library and Portal
run: yarn build
- name: Unit Tests
run: yarn test:ci
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v3
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
file: .conf/Dockerfile.prebuilt
push: true
# build tag :dev with commit-sha and latest
tags: ${{ steps.meta.outputs.tags }}_${{ env.COMMIT_SHA }}, ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
labels: ${{ steps.meta.outputs.labels }}
auth-and-dispatch:
needs: build-and-push-image
runs-on: ubuntu-latest
steps:
- name: Get token
id: get_workflow_token
uses: peter-murray/workflow-application-token-action@v1
with:
application_id: ${{ secrets.ORG_PORTAL_DISPATCH_APPID }}
application_private_key: ${{ secrets.ORG_PORTAL_DISPATCH_KEY }}
# The triggered workflow isn't enabled for branch names / github.ref_name containing special characters like '/' for example 'feature/...'
- name: Trigger workflow
id: call_action
env:
TOKEN: ${{ steps.get_workflow_token.outputs.token }}
run: |
curl -v \
--request POST \
--url https://api.github.com/repos/catenax-ng/product-portal-cd/actions/workflows/portal-image-update.yml/dispatches \
--header "authorization: Bearer $TOKEN" \
--header "Accept: application/vnd.github.v3+json" \
--data '{"ref":"main", "inputs": { "new-image":"${{ github.ref_name }}_${{ env.COMMIT_SHA }}" }}' \
--fail