-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yaml
More file actions
183 lines (158 loc) · 6.3 KB
/
Copy pathaction.yaml
File metadata and controls
183 lines (158 loc) · 6.3 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
name: Frontend Build-Action
description: 'build and push to s3'
inputs:
PAT:
description: 'PAT from repo'
required: true
NODE_VERSION:
description: 'node version'
required: false
default: 'latest'
WORKING_DIRECTORY:
description: 'working directory'
required: true
default: ''
MONOREPO_MODE:
description: 'monorepo mode'
required: false
default: 'false'
BUCKET_NAME:
description: 'bucket name'
required: true
OUTPUT_PATH:
description: 'output path'
required: false
default: 'dist'
outputs:
bucket_name:
description: 'bucket_name'
value: ${{ steps.bucket_name.outputs.bucket_name }}
runs:
using: 'composite'
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Use Node.js ${{ inputs.NODE_VERSION }}
uses: actions/setup-node@v6
with:
node-version: ${{ inputs.NODE_VERSION }}
cache: 'npm'
- name: Authenticate with private NPM package
run: |
echo "@entrecode:registry=https://npm.pkg.github.com/" > ./.npmrc
echo "//npm.pkg.github.com/:_authToken=${{ inputs.PAT }}" > ./.npmrc
working-directory: ${{ inputs.MONOREPO_MODE == 'true' && github.workspace || format('{0}/{1}', github.workspace, inputs.WORKING_DIRECTORY) }}
shell: bash
- name: Check file existence pnpm
id: check_files_pnpm
uses: andstor/file-existence-action@v3
with:
files: 'pnpm-lock.*'
- name: check packageManager in package.json
if: steps.check_files_pnpm.outputs.files_exists == 'true'
run: |
set -euo pipefail
PACKAGE_MANAGER=$(jq -er '.packageManager' package.json) || {
echo "packageManager field missing in package.json"
echo "Add: \"packageManager\": \"pnpm@<version>\" and execute 'corepack use pnpm@latest-<version>' in terminal"
exit 1
}
if [[ ! "$PACKAGE_MANAGER" =~ ^pnpm@ ]]; then
echo "packageManager is set but not matching required pattern 'pnpm@...'"
echo "Current value: $PACKAGE_MANAGER"
echo "Expected: \"pnpm@<version>\""
echo "packageManager is set but not matching required pattern 'pnpm@...'"
echo "Add: \"packageManager\": \"pnpm@<version>\" and execute 'corepack use pnpm@latest-<version>' in terminal"
exit 1
fi
echo "✔ packageManager ok: $PACKAGE_MANAGER"
shell: bash
- name: Setup pnpm
if: steps.check_files_pnpm.outputs.files_exists == 'true'
uses: pnpm/action-setup@v5
- name: Install pnpm
if: steps.check_files_pnpm.outputs.files_exists == 'true'
run: pnpm install --frozen-lockfile --prefer-offline --reporter=silent
shell: bash
- name: Install Dependencies
if: steps.check_files_pnpm.outputs.files_exists != 'true'
run: npm ci --prefer-offline --no-audit --quiet
working-directory: ${{ inputs.MONOREPO_MODE == 'true' && github.workspace || format('{0}/{1}', github.workspace, inputs.WORKING_DIRECTORY) }}
shell: bash
- name: Build stage with pnpm
if: steps.check_files_pnpm.outputs.files_exists == 'true' && startsWith(github.ref, 'refs/tags/') != true && startsWith(github.ref, 'refs/heads/release/') != true
id: build_stage_pnpm
env:
NODE_OPTIONS: '--max_old_space_size=8192'
run: |
pnpm run stage
echo "bucket_name=${{ inputs.BUCKET_NAME }}-stage" >> $GITHUB_OUTPUT
working-directory: ${{ github.workspace }}/${{ inputs.WORKING_DIRECTORY }}
shell: bash
- name: Build stage with npm
if: steps.check_files_pnpm.outputs.files_exists != 'true' && startsWith(github.ref, 'refs/tags/') != true && startsWith(github.ref, 'refs/heads/release/') != true
id: build_stage
env:
NODE_OPTIONS: '--max_old_space_size=8192'
run: |
npm run stage
echo "bucket_name=${{ inputs.BUCKET_NAME }}-stage" >> $GITHUB_OUTPUT
working-directory: ${{ github.workspace }}/${{ inputs.WORKING_DIRECTORY }}
shell: bash
- name: Build staging with pnpm
if: steps.check_files_pnpm.outputs.files_exists == 'true' && startsWith(github.ref, 'refs/heads/release/')
id: build_staging_pnpm
env:
NODE_OPTIONS: '--max_old_space_size=8192'
run: |
pnpm run staging
echo "bucket_name=${{ inputs.BUCKET_NAME }}-staging" >> $GITHUB_OUTPUT
working-directory: ${{ github.workspace }}/${{ inputs.WORKING_DIRECTORY }}
shell: bash
- name: Build staging with npm
if: steps.check_files_pnpm.outputs.files_exists != 'true' && startsWith(github.ref, 'refs/heads/release/')
id: build_staging
env:
NODE_OPTIONS: '--max_old_space_size=8192'
run: |
npm run staging
echo "bucket_name=${{ inputs.BUCKET_NAME }}-staging" >> $GITHUB_OUTPUT
working-directory: ${{ github.workspace }}/${{ inputs.WORKING_DIRECTORY }}
shell: bash
- name: Build prod with pnpm
if: steps.check_files_pnpm.outputs.files_exists == 'true' && startsWith(github.ref, 'refs/tags/')
id: build_prod_pnpm
env:
NODE_OPTIONS: '--max_old_space_size=8192'
run: |
pnpm run prod
echo "bucket_name=${{ inputs.BUCKET_NAME }}-prod" >> $GITHUB_OUTPUT
working-directory: ${{ github.workspace }}/${{ inputs.WORKING_DIRECTORY }}
shell: bash
- name: Build prod with npm
if: steps.check_files_pnpm.outputs.files_exists != 'true' && startsWith(github.ref, 'refs/tags/')
id: build_prod
env:
NODE_OPTIONS: '--max_old_space_size=8192'
run: |
npm run prod
echo "bucket_name=${{ inputs.BUCKET_NAME }}-prod" >> $GITHUB_OUTPUT
working-directory: ${{ github.workspace }}/${{ inputs.WORKING_DIRECTORY }}
shell: bash
- name: Create Bucket Name Output
id: bucket_name
run: echo "bucket_name=${{ steps.build_stage.outputs.bucket_name || steps.build_staging.outputs.bucket_name || steps.build_prod.outputs.bucket_name || steps.build_stage_pnpm.outputs.bucket_name || steps.build_staging_pnpm.outputs.bucket_name || steps.build_prod_pnpm.outputs.bucket_name }}" >> $GITHUB_OUTPUT
shell: bash
- name: check bucket_name
run: |
if [[ -z "${{ steps.bucket_name.outputs.bucket_name }}" ]]; then
echo "bucket_name input is required, it is currently empty"
exit 1
fi
shell: bash
- name: Upload build artifact
uses: actions/upload-artifact@v7
with:
name: build_result
path: ${{ github.workspace }}/${{ inputs.WORKING_DIRECTORY }}/${{ inputs.OUTPUT_PATH }}/
retention-days: 2