-
-
Notifications
You must be signed in to change notification settings - Fork 400
187 lines (166 loc) · 5.93 KB
/
deploy.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
---
name: Deploy
on:
push:
branches:
- develop
- deploy
tags:
# only tags with semver format
- '[0-9]+.[0-9]+.[0-9]+'
workflow_dispatch:
jobs:
create-signed-phar-file:
runs-on: ubuntu-latest
steps:
- name: Checkout HEAD
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
tools: composer:2
php-version: '7.4'
# Allow only newer versions
- name: Collect versions
run: |
# extract tag part of github.ref
PUSHED_VERSION=$(cut -d'/' -f3 <<< "$GITHUB_REF")
LATEST_RELEASED_VERSION=$(curl -s https://raw.githubusercontent.com/netz98/n98-magerun/master/version.txt | tr -d '[:space:]')
echo "pushed_version=$PUSHED_VERSION" >> $GITHUB_ENV
echo "latest_released_version=$LATEST_RELEASED_VERSION" >> $GITHUB_ENV
- uses: jackbilestech/semver-compare@1.0.4
if: startsWith(github.ref, 'refs/tags/')
with:
head: '${{ env.pushed_version }}'
base: '${{ env.latest_released_version }}'
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest
- name: Create phar
run: bash ./build.sh
- name: Run phar file
run: php n98-magerun.phar --version
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.GPG_PASSPHRASE }}
- name: GPG sign phar file (detached)
run: |
echo "${{ secrets.GPG_PASSPHRASE }}" | \
gpg --batch --yes --pinentry-mode loopback --passphrase-fd 0 --detach-sign -a \
-o n98-magerun.phar.asc n98-magerun.phar
env:
GPG_TTY: $(tty)
- name: GPG verify phar file
run: gpg --verify n98-magerun.phar.asc n98-magerun.phar
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: n98-magerun.phar
path: |
n98-magerun.phar
n98-magerun.phar.asc
update-files-magerun-net:
runs-on: ubuntu-latest
needs: ["create-signed-phar-file"]
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: n98-magerun.phar
path: .
- name: rename phar file (deploy test)
if: github.ref == 'refs/heads/deploy'
run: |
TAG=deploy-test-1.2.3
mv n98-magerun.phar n98-magerun-${TAG}.phar
mv n98-magerun.phar.asc n98-magerun-${TAG}.phar.asc
ls -l
- name: rename phar file (develop / unstable)
if: github.ref == 'refs/heads/develop'
run: |
mv n98-magerun.phar n98-magerun-dev.phar
mv n98-magerun.phar.asc n98-magerun-dev.phar.asc
ls -l
- name: rename phar file (tag)
if: startsWith(github.ref, 'refs/tags/')
run: |
# get tag part of github.ref
TAG=$(cut -d'/' -f3 <<< "$GITHUB_REF")
cp n98-magerun.phar n98-magerun-${TAG}.phar
cp n98-magerun.phar.asc n98-magerun-${TAG}.phar.asc
mv n98-magerun.phar n98-magerun-latest.phar
mv n98-magerun.phar.asc n98-magerun-latest.phar.asc
ls -l
- name: Upload phar file to files.magerun.net
uses: appleboy/scp-action@master
with:
host: ${{ secrets.SSH_DEPLOY_HOST }}
username: ${{ secrets.SSH_DEPLOY_USERNAME }}
key: ${{ secrets.SSH_DEPLOY_PRIVATE_KEY }}
passphrase: ${{ secrets.SSH_DEPLOY_PASSPHRASE }}
source: '*.phar,*.phar.asc'
target: ${{ secrets.SSH_DEPLOY_TARGET }}
rm: false
overwrite: true
- name: Run update tasks on files.magerun.net
uses: appleboy/ssh-action@v1.1.0
with:
host: ${{ secrets.SSH_DEPLOY_HOST }}
username: ${{ secrets.SSH_DEPLOY_USERNAME }}
key: ${{ secrets.SSH_DEPLOY_PRIVATE_KEY }}
passphrase: ${{ secrets.SSH_DEPLOY_PASSPHRASE }}
script: |
build/build_phive.sh
curl -s https://files.magerun.net/list.php > public/index.html
- name: Invalidate cloudflare
run: |
curl -X POST 'https://api.cloudflare.com/client/v4/zones/${{ secrets.CLOUDFLARE_ZONE }}/purge_cache' \
-H 'Content-Type:application/json' \
-H "Authorization: Bearer ${{ secrets.CLOUDFLARE_TOKEN }}" \
--data-raw '{"purge_everything":true}'
update-dist-repo:
runs-on: ubuntu-latest
needs: [ "create-signed-phar-file" ]
steps:
- name: Checkout HEAD
uses: actions/checkout@v4
- uses: webfactory/ssh-agent@v0.9.0
with:
ssh-private-key: ${{ secrets.DIST_REPO_DEPLOY_KEY }}
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: n98-magerun.phar
- name: Update dist repo
env:
GIT_USER_EMAIL: ${{ secrets.GIT_USER_EMAIL }}
GIT_USER_NAME: ${{ secrets.GIT_USER_NAME }}
run: bash .github/workflows/update-dist-repo.sh
create-github-release:
runs-on: ubuntu-latest
needs: [ "create-signed-phar-file" ]
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Checkout HEAD
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
with:
name: n98-magerun.phar
- name: 'Build Changelog'
uses: mikepenz/release-changelog-builder-action@v5
with:
owner: "netz98"
repo: "n98-magerun"
id: build_changelog
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Release
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
body: ${{steps.build_changelog.outputs.changelog}}
files: |
n98-magerun.phar
n98-magerun.phar.asc