-
Notifications
You must be signed in to change notification settings - Fork 4
112 lines (99 loc) · 3.62 KB
/
assets-compilation.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
name: Assets compilation
on:
workflow_call:
inputs:
COMPOSER_VERBOSITY:
description: Verbosity of Composer output, without the leading dash.
default: v
required: false
type: string
NPM_REGISTRY_SCOPE:
description: Name of the private npm registry scope, including the character "@".
default: '@inpsyde'
required: false
type: string
NPM_REGISTRY_DOMAIN:
description: Domain of the private npm registry, without trailing slash.
default: https://npm.pkg.github.com
required: false
type: string
NODE_VERSION:
description: Node version with which the assets will be compiled.
default: 16
required: false
type: string
PHP_VERSION:
description: PHP version with which the Composer Asset Compiler is to be executed.
default: 7.4
required: false
type: string
secrets:
COMPOSER_AUTH_JSON:
description: Authentication for privately hosted packages and repositories as a JSON formatted object.
required: false
NPM_REGISTRY_TOKEN:
description: Authentication for the private npm registry.
required: false
jobs:
assets-compilation:
timeout-minutes: 5
runs-on: ubuntu-latest
env:
COMPOSER_AUTH: '${{ secrets.COMPOSER_AUTH_JSON }}'
NODE_AUTH_TOKEN: ${{ secrets.NPM_REGISTRY_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up node
uses: actions/setup-node@v3
with:
node-version: ${{ inputs.NODE_VERSION }}
registry-url: ${{ inputs.NPM_REGISTRY_DOMAIN }}
- name: Set up PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.PHP_VERSION }}
tools: composer
- uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Composer dependencies
uses: ramsey/composer-install@v1
with:
composer-options: "--prefer-dist"
- name: Extract package hash into env [DEV]
if: ${{ !contains(github.ref, 'refs/tags/') }}
run: echo "ASSETS_HASH=$(composer assets-hash)" >> $GITHUB_ENV
- name: Extract tag name into env [PROD]
if: ${{ contains(github.ref, 'refs/tags/') }}
run: echo "TAG_NAME=$(echo ${GITHUB_REF#refs/*/})" >> $GITHUB_ENV
- name: Set ENCORE_ENV to production [PROD]
if: ${{ contains(github.ref, 'refs/tags/') }}
run: echo "ENCORE_ENV=production" >> $GITHUB_ENV
- name: Compile assets
run: composer -${{ inputs.COMPOSER_VERBOSITY }} compile-assets --env=root
- name: Upload assets artifact [DEV]
uses: actions/upload-artifact@v3
if: ${{ !contains(github.ref, 'refs/tags/') }}
with:
name: assets-${{ env.ASSETS_HASH }}
path: assets
- name: Zip assets folder [PROD]
uses: montudor/action-zip@v1
if: ${{ contains(github.ref, 'refs/tags/') }}
with:
args: zip -qq -r assets-${{ env.TAG_NAME }}.zip assets
- name: Upload release attachment [PROD]
if: ${{ contains(github.ref, 'refs/tags/') }}
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: assets-${{ env.TAG_NAME }}.zip
tag: ${{ github.ref }}
overwrite: true
body: |
# ${{ env.TAG_NAME }}
Compiled assets available in `assets-${{ env.TAG_NAME }}.zip`.