forked from concretecms/concretecms
-
Notifications
You must be signed in to change notification settings - Fork 0
86 lines (84 loc) · 3.22 KB
/
build-assets.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
name: Build assets
on:
pull_request:
push:
branches:
- "**"
tags-ignore:
- "**"
jobs:
build-assets:
strategy:
matrix:
include:
- os: ubuntu-latest
nodejs-version: 18
# Just one case may have this set to yes
update-repo: yes
name: Build assets (node ${{ matrix.nodejs-version }} on ${{ matrix.os }})
runs-on: ${{ matrix.os }}
steps:
- name: Setup NodeJS
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.nodejs-version }}
- name: Checkout
uses: actions/checkout@v3
- name: Install NodeJS dependencies
run: |
cd "${{ github.workspace }}/build"
npm ci
- name: Build assets (dev)
run: |
cd "${{ github.workspace }}/build"
npm run-script dev
- name: Tell git to ignore the built files
run: |
cd "${{ github.workspace }}/build"
npm run-script git-skip
- name: Check that git thinks the repo is clean
run: |
cd "${{ github.workspace }}"
git diff --exit-code --name-status
- name: Revert changed files
run: |
cd "${{ github.workspace }}/build"
npm run-script git-revert
- name: Check that git thinks the repo is clean
run: |
cd "${{ github.workspace }}"
git diff --exit-code --name-status
- name: Build assets (prod)
run: |
cd "${{ github.workspace }}/build"
npm run-script prod
- name: Check if we need to create a pull request
if: matrix.update-repo == 'yes'
id: pr-test
run: |
cd '${{ github.workspace }}'
if git diff --exit-code --name-status; then
echo "We won't create a pull request because no change has been detected"
elif [ '${{ github.event_name }}' != 'push' ]; then
echo "We won't create a pull request because it's a '${{ github.event_name }}' operation and not a 'push' one"
elif [ '${{ github.repository }}' != 'concretecms/concretecms' ]; then
echo "We won't create a pull request because the current repository is '${{ github.repository }}' and not 'concretecms/concretecms'"
else
echo 'Changes detected and pull request needed!'
echo "result=yes" >>"$GITHUB_OUTPUT"
echo "branch-name=auto-assets/$(date --utc +%Y%m%d-%H%M%S)" >>"$GITHUB_OUTPUT"
fi
- name: Create pull request
id: pr-create
if: steps.pr-test.outputs.result == 'yes'
uses: peter-evans/create-pull-request@v5
with:
commit-message: Automatic assets rebuilding
committer: GitHub Action <[email protected]>
author: GitHub Action <[email protected]>
branch: '${{ steps.pr-test.outputs.branch-name }}'
title: "Automatic assets rebuilding for ${{ github.ref_name }}"
body: "Created by ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
- name: Pull request info
if: steps.pr-test.outputs.result == 'yes'
run: printf 'Pull request created:\n%s' "${{ steps.pr-create.outputs.pull-request-url }}"