-
Notifications
You must be signed in to change notification settings - Fork 3
97 lines (95 loc) · 3.14 KB
/
setup-project.yml
File metadata and controls
97 lines (95 loc) · 3.14 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
name: Setup Project and Node Environment
on:
workflow_call:
inputs:
main-branch:
description: 'Whether to utilise the main branch or the current branch'
default: false
required: false
type: boolean
write:
description: 'Whether write permissions will be required.'
default: false
required: false
type: boolean
production:
description: 'Whether this is a production environment or not'
default: false
required: false
type: boolean
build:
description: 'Whether the project is to be built or not'
default: false
required: false
type: boolean
outputs:
export-dir:
value: ${{ jobs.setup-project.outputs.export-dir }}
jobs:
setup-project:
runs-on: ubuntu-latest
outputs:
export-dir: ${{ steps.output-dir.outputs.export-dir }}
steps:
- name: Checkout Main Branch no Write
if: ${{ inputs.main-branch == true && inputs.write == false }}
uses: actions/checkout@v3
with:
ref: main
persist-credentials: false
submodules: recursive
- name: Checkout Main Branch with Write
if: ${{ inputs.main-branch == true && inputs.write == true }}
uses: actions/checkout@v3
with:
ref: main
token: ${{ secrets.COMMIT_TOKEN }}
persist-credentials: true
submodules: recursive
- name: Checkout Branch no Write
if: ${{ inputs.main-branch != true && inputs.write == false }}
uses: actions/checkout@v3
with:
persist-credentials: false
submodules: recursive
- name: Checkout Branch with Write
if: ${{ inputs.main-branch != true && inputs.write == true }}
uses: actions/checkout@v3
with:
token: ${{ secrets.COMMIT_TOKEN }}
persist-credentials: true
submodules: recursive
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: 16
- name: Set Production Environment Variable
if: ${{ inputs.production == true }}
run: echo "NODE_ENV=production" >> $GITHUB_ENV
- name: Install Node Packages
run: npm ci
- name: Build Project
if: ${{ inputs.build == true }}
run: npm run build
- name: Set Artifact Name
run: |
if [[ ${{ inputs.build }} == 'true' ]]; then
export "BUILT=build"
else
export "BUILT=source"
fi
echo "BUILD_NAME=$BUILT-${{ github.sha }}" >> $GITHUB_ENV
- name: Tarball Build Files for Export
if: ${{ inputs.build == true }}
run: tar -cvf ${{ env.BUILD_NAME }}.tar dist
- name: Tarball Source Files for Export
if: ${{ inputs.build != true }}
run: tar -cvf ${{ env.BUILD_NAME }}.tar ./
- name: Export Artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.BUILD_NAME }}
path: ${{ env.BUILD_NAME }}.tar
- name: Output Directory Name
id: output-dir
run: echo '::set-output name=export-dir::${{ env.BUILD_NAME }}'