forked from brol/construction
-
Notifications
You must be signed in to change notification settings - Fork 0
165 lines (151 loc) · 6.12 KB
/
release.yml
File metadata and controls
165 lines (151 loc) · 6.12 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
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
name: Release package
on:
push:
workflow_dispatch:
env:
DC_TYPE: plugin
DC_MIN: 2.28
# required to set secrets in
# https://github.com/xxx/xxx/settings/secrets/actions
# TELEGRAM_ID, TELEGRAM_TOKEN
jobs:
check_release:
if: (startsWith(github.event.head_commit.message, 'release ') || (github.event_name != 'push'))
runs-on: ubuntu-latest
outputs:
version: ${{ steps.dotclear.outputs.version }}
dcmin: ${{ steps.dotclear.outputs.dcmin }}
exists: ${{ steps.repository.outputs.release-exists }}
steps:
- name: Checkout repository master branch
uses: actions/checkout@master
# Parser from https://github.com/franck-paul
- name: Run PHP code
id: dotclear
shell: php {0}
run: |
<?php
$version = substr('${{ github.event.head_commit.message }}', 8);
$dcmin = '${{ env.DC_MIN }}';
$df = file_get_contents('./_define.php');
if (preg_match('/registerModule\((.*?),(.*?)[\'\"],(.*?)[\'\"],(.*?)[\'\"](.*?)[\'\"](.*?)(,.*)\)/s',$df,$matches)) {
if (isset($matches[7]) && preg_match('/\[(.*?)[\'\"]core[\'\"](.*?),(.*?)[\'\"](.*?)[\'\"](.*?)\]/s',$matches[7],$submatches)) {
$dcmin = $submatches[4];
}
}
file_put_contents(getenv('GITHUB_OUTPUT'), "version=$version\ndcmin=$dcmin\n", FILE_APPEND);
- name: Check repository releases
id: repository
uses: insightsengineering/release-existence-action@v1.0.0
with:
release-tag: 'v${{ steps.dotclear.outputs.version }}'
do_release:
needs: check_release
if: needs.check_release.outputs.exists == 'false'
runs-on: ubuntu-latest
steps:
- name: Checkout repository master branch
uses: actions/checkout@master
- name: Get repository name
id: repository
uses: MariachiBear/get-repo-name-action@v1.1.0
with:
with-owner: 'false'
- name: Import GPG key
id: import-gpg
uses: crazy-max/ghaction-import-gpg@v6
with:
gpg_private_key: ${{ secrets.BOT_GPG_KEY }}
passphrase: ${{ secrets.BOT_GPG_PASS }}
git_config_global: true
git_user_signingkey: true
git_commit_gpgsign: true
- name: Get download URL
id: download
run: |
fulltag=${{ github.ref_name }}
echo download-url="https://github.com/${{ github.repository }}/releases/download/v${{ needs.check_release.outputs.version }}/${{ env.DC_TYPE }}-${{ steps.repository.outputs.repository-name }}.zip" >> $GITHUB_OUTPUT
# Parser from https://github.com/franck-paul
- name: Update version and date
id: updatefiles
shell: php {0}
run: |
<?php
$version = '${{ needs.check_release.outputs.version }}';
$date = date('c');
if (file_exists('_define.php')) {
$ds = file_get_contents('_define.php');
if ($ds) {
$ds = preg_replace('/^(.*registerModule\(.*?,.*?[\'\"],.*?[\'\"],.*?)([\'\"].*?[\'\"])(.*?,.*\).*)$/s',"$1'".$version."'$3",$ds);
$ds = preg_replace('/(\'date\'\s+=>\s)(\'.*?\')/s',"$1'".$date."'",$ds);
if ($ds) {
file_put_contents('_define.php',$ds);
}
}
}
if (file_exists('dcstore.xml')) {
$ds = file_get_contents('dcstore.xml');
if ($ds) {
$ds = preg_replace('/<version>(.*?)<\/version>/s',"<version>".$version."</version>",$ds);
$ds = preg_replace('/<file>(.*?)<\/file>/s',"<file>${{ steps.download.outputs.download-url }}</file>",$ds);
$ds = preg_replace('/<date>(.*?)<\/date>/s',"<date>".$date."</date>",$ds);
$ds = preg_replace('/<da:dcmin>(.*?)<\/da:dcmin>/s',"<da:dcmin>${{ needs.check_release.outputs.dcmin }}</da:dcmin>",$ds);
if ($ds) {
file_put_contents('dcstore.xml',$ds);
}
}
}
- name: Write files
id: writefiles
shell: bash
run: |
test=$(git diff --name-only -- _define.php)
if [[ "$test" != "" ]]; then
echo "_define.php modified, need to be commit"
git add _define.php
git commit -S -m "Update _define.php for release"
git push
else
echo "_define.php not modified"
fi
test=$(git diff --name-only -- dcstore.xml)
if [[ "$test" != "" ]]; then
echo "dcstore.xml modified, need to be commit"
git add dcstore.xml
git commit -S -m "Update dcstore.xml for release"
git push
else
echo "dcstore.xml not modified"
fi
- name: Create archive
id: writearchive
uses: thedoctor0/zip-release@0.7.6
with:
type: 'zip'
directory: ..
path: '${{ steps.repository.outputs.repository-name }}'
filename: '${{ env.DC_TYPE }}-${{ steps.repository.outputs.repository-name }}.zip'
exclusions: '*.git* /*node_modules/* .editorconfig'
- name: Create release with archive
id: writerelease
uses: ncipollo/release-action@v1.14.0
with:
artifacts: '../${{ env.DC_TYPE }}-${{ steps.repository.outputs.repository-name }}.zip'
token: ${{ secrets.GITHUB_TOKEN }}
commit: master
draft: false
prerelease: false
generateReleaseNotes: true
name: ${{ steps.repository.outputs.repository-name }} ${{ needs.check_release.outputs.version }}
tag: 'v${{ needs.check_release.outputs.version }}'
- name: Send Telegram Message Ok
uses: appleboy/telegram-action@v1.0.0
with:
to: ${{ secrets.TELEGRAM_ID }}
token: ${{ secrets.TELEGRAM_TOKEN }}
format: markdown
message: |
__Github workflow run__
- Trigger: ${{ github.event_name }}
- Release: ${{ steps.repository.outputs.repository-name }} ${{ needs.check_release.outputs.version }}
- Download URL: ${{ steps.download.outputs.download-url }}