-
Notifications
You must be signed in to change notification settings - Fork 1
166 lines (155 loc) · 5.91 KB
/
auto-minify.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
name: Minify Assets Files(css/js) and Deploy to Stage
on:
push:
branches:
- main
pull_request:
jobs:
minify-css-and-js:
name: Minify CSS and JS files
runs-on: ubuntu-latest
steps:
- name: Checkout Actions
if: github.event_name == 'pull_request'
uses: actions/checkout@v4
with:
ref: ${{github.head_ref}}
persist-credentials: false
- name: Checkout Actions (main)
if: github.ref == 'refs/heads/main'
uses: actions/checkout@v4
with:
ref: ${{github.ref}}
persist-credentials: false
- name: Auco Minify JS
uses: nizarmah/auto-minify@master
with:
directory: "themes/vald/static/js"
- name: Auco Minify CSS
uses: nizarmah/auto-minify@master
with:
directory: "themes/vald/static/css"
- name: Check Changes
id: git_diff_static
run: |
diff=`git diff themes/vald/static/`
if [ ! -z "$diff" ] ; then \
echo "diff=true" >> $GITHUB_OUTPUT
fi
- name: Commit Minified Files (pull_request)
if: steps.git_diff_static.outputs.diff == 'true' && github.event_name== 'pull_request'
run: |
git config --global user.name "vdaas-ci"
git config --global user.email "[email protected]"
git add themes/vald/static
git commit --signoff -m ":robot: auto update minified files :recycle:"
git remote set-url origin "https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
git push origin ${{ github.head_ref }}
env:
GITHUB_USER: ${{ secrets.DISPATCH_USER }}
GITHUB_TOKEN: ${{ secrets.DISPATCH_TOKEN }}
- name: Commit Minified Files (main)
if: steps.git_diff_static.outputs.diff == 'true' && github.ref == 'refs/heads/main'
run: |
git config --global user.name "vdaas-ci"
git config --global user.email "[email protected]"
git checkout main
git add themes/vald/static
git commit --signoff -m ":robot: auto update minified files :recycle:"
git remote set-url origin "https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
git push origin main
env:
GITHUB_USER: ${{ secrets.DISPATCH_USER }}
GITHUB_TOKEN: ${{ secrets.DISPATCH_TOKEN }}
deploy-stage:
name: Deploy to Stage Env
runs-on: ubuntu-latest
needs:
- minify-css-and-js
steps:
- name: Checkout Actions
if: github.event_name == 'pull_request'
uses: actions/checkout@v4
with:
ref: ${{github.head_ref}}
persist-credentials: false
- name: Checkout Actions (main)
if: github.ref == 'refs/heads/main'
uses: actions/checkout@v4
with:
ref: ${{github.ref}}
persist-credentials: false
- name: Setup Hugo
uses: peaceiris/actions-hugo@v2
with:
hugo-version: latest
- name: Setup for Build
if: github.event_name == 'pull_request'
run: |
git config --global user.name "vdaas-ci"
git config --global user.email "[email protected]"
git remote set-url origin "https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
git pull origin ${{ github.head_ref }}
git submodule update --init --recursive
cd preview
git remote set-url origin "https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
git checkout gh-pages
git pull origin gh-pages
env:
GITHUB_USER: ${{ secrets.DISPATCH_USER }}
GITHUB_TOKEN: ${{ secrets.DISPATCH_TOKEN }}
- name: Setup for Build (main)
if: github.ref == 'refs/heads/main'
run: |
git config --global user.name "vdaas-ci"
git config --global user.email "[email protected]"
git remote set-url origin "https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
git pull origin main
git submodule update --init --recursive
cd preview
git remote set-url origin "https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
git checkout gh-pages
git pull origin gh-pages
env:
GITHUB_USER: ${{ secrets.DISPATCH_USER }}
GITHUB_TOKEN: ${{ secrets.DISPATCH_TOKEN }}
- name: Stage Build
run: |
make build/stage
- name: Check Changes preview
id: git_diff_preview
run: |
diff=`git diff preview/`
if [ ! -z "$diff" ] ; then \
echo "diff=true" >> $GITHUB_OUTPUT
fi
- name: Stage Deploy
if: steps.git_diff_preview.outputs.diff == 'true'
run: |
export LATEST_VERSION=$(make version/latest)
cd preview
git checkout gh-pages
git add .
git commit --signoff -m ":arrow_up: v${LATEST_VERSION} `date`"
git push origin gh-pages
env:
GITHUB_USER: ${{ secrets.DISPATCH_USER }}
GITHUB_TOKEN: ${{ secrets.DISPATCH_TOKEN }}
- name: Commit Stage Changes
if: steps.git_diff_preview.outputs.diff == 'true' && github.event_name == 'pull_request'
run: |
git add preview
git commit --signoff -m ":robot: auto update stage :arrow_up:"
git push origin ${{ github.head_ref }}
env:
GITHUB_USER: ${{ secrets.DISPATCH_USER }}
GITHUB_TOKEN: ${{ secrets.DISPATCH_TOKEN }}
- name: Commit Stage Changes (main)
if: steps.git_diff_preview.outputs.diff == 'true' && github.ref == 'refs/heads/main'
run: |
git add preview
git commit --signoff -m ":robot: auto update stage :arrow_up:"
git push origin main
env:
GITHUB_USER: ${{ secrets.DISPATCH_USER }}
GITHUB_TOKEN: ${{ secrets.DISPATCH_TOKEN }}