-
Notifications
You must be signed in to change notification settings - Fork 14
143 lines (123 loc) · 4.38 KB
/
eo-cd.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# Copyright 2020 Energinet DataHub A/S
#
# Licensed under the Apache License, Version 2.0 (the "License2");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Energy Origin CD
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
app-name: app-eo
landing-page-app-name: app-eo-landing-page
BASE_BRANCH: ${{ github.event.pull_request.base.ref }}
is-main-branch: ${{ github.ref == 'refs/heads/main' }}
is-pull-request: ${{ github.event_name == 'pull_request' }}
# Nx Cloud
NX_BRANCH: ${{ github.event.number }}
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
NX_RUN_GROUP: ${{ github.run_id }}
on:
push:
branches:
- main
pull_request: {}
jobs:
affected:
name: Is affected?
runs-on: ubuntu-latest
outputs:
is-affected: ${{ steps.affected.outputs.is-affected }}
steps:
# needed for nx affected command
- name: Check out source code with current branch Git history
uses: actions/checkout@v4
with:
fetch-depth: 0
# needed for nx affected command
- name: "PR: Fetch base branch Git history"
if: ${{ env.is-pull-request == 'true' }}
run: git fetch --no-tags origin $BASE_BRANCH
- name: Bun setup
uses: oven-sh/setup-bun@v2
with:
bun-version-file: package.json
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Prepare projects array
id: prepare
run: echo "projects=[\"${{ env.app-name }}\", \"${{ env.landing-page-app-name }}\"]" >> $GITHUB_OUTPUT
- name: Is affected?
id: affected
uses: ./.github/actions/affected
with:
base: ${{ env.is-main-branch == 'true' && 'HEAD~1' || format('origin/{0}', env.BASE_BRANCH) }}
projects: ${{ steps.prepare.outputs.projects }}
app:
name: Build app
if: ${{ needs.affected.outputs.is-affected == 'true' }}
needs: affected
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Bun setup
uses: oven-sh/setup-bun@v2
with:
bun-version-file: package.json
- name: Install dependencies
run: bun install --frozen-lockfile
- name: Production build
run: bun run nx build ${{ env.app-name }}
- name: Upload web app build artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.app-name }}
path: ./dist/apps/eo/
if-no-files-found: error
define_build:
name: Define build
needs: affected
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Generate version
id: version
uses: Energinet-DataHub/acorn-actions/actions/docker-image-version@v3
build:
runs-on: ubuntu-latest
name: Build
needs:
- define_build
- app
steps:
- uses: actions/checkout@v4
- name: Build and push container image
id: docker_build
uses: Energinet-DataHub/acorn-actions/actions/docker-build-and-push@v3
with:
dockerfile: build/infrastructure/eo/host/Dockerfile
image-name: eo-frontend-app
image-tag: ${{ needs.define_build.outputs.version }}
update-environment:
name: Update environment
runs-on: ubuntu-latest
needs:
- build
concurrency: commits-base-environment
steps:
- name: Update environment
uses: Energinet-DataHub/acorn-actions/actions/update-base-environment@v3
with:
configuration: build/infrastructure/eo/configuration.yaml
deploy_key: ${{ secrets.DEPLOY_KEY_BASE_ENVIRONMENT }}
dry_run: ${{ !((github.event_name == 'push' && github.ref_name == 'main') || (github.event_name == 'pull_request' && startsWith(github.event.pull_request.head.ref, 'preview/')) || (github.event_name == 'pull_request' && startsWith(github.event.pull_request.head.ref, 'vcluster/'))) }}