-
Notifications
You must be signed in to change notification settings - Fork 44
67 lines (54 loc) · 4.25 KB
/
release-cron.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
name: release-cron
on:
schedule:
- cron: "0 12 * * 2,5" # 每周二和周五的12点(UTC时间)
workflow_dispatch:
jobs:
create_release:
name: get version and create release
runs-on: ubuntu-latest
steps:
- name: version check
id: version
run: |
# 获取已经 release 的版本
releasedVersion=$(wget -qO- -t3 -T30 "https://api.github.com/repos/${GITHUB_REPOSITORY}/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g')
# 获取最新代码的版本
packageJson=$(wget -qO- -t3 -T30 "https://raw.githubusercontent.com/siyuan-note/siyuan/master/app/package.json")
packageVersion=$(echo "${packageJson}" | grep "version" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g')
# 设置输出
if [ "${releasedVersion}" = "v${packageVersion}" ]; then
echo "release_version=0" >> $GITHUB_OUTPUT
else
echo "release_version=v${packageVersion}" >> $GITHUB_OUTPUT
fi
packageManager=$(echo "${packageJson}" | grep "packageManager" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g')
echo "package_manager=${packageManager}" >> $GITHUB_OUTPUT
echo "releasedVersion: ${releasedVersion}"
echo "packageVersion: ${packageVersion}"
echo "packageManager: ${packageManager}"
- name: Create Release
id: create_release
uses: ncipollo/release-action@v1
if: ${{ steps.version.outputs.release_version != '0' }}
with:
name: ${{ steps.version.outputs.release_version }}
tag: ${{ steps.version.outputs.release_version }}
body: "action release"
draft: false
prerelease: false
token: ${{ secrets.GITHUB_TOKEN }}
- name: dispatch release
if: ${{ steps.version.outputs.release_version != '0' }}
run: |
sudo apt install jq
response=$(curl --request GET --url https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/workflows --header 'Accept: application/vnd.github+json' --header 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' --header 'X-GitHub-Api-Version: 2022-11-28')
androidId=$(echo "$response" | jq -r '.workflows | .[] | select(.path | contains("release-android.yml")) | .id')
pcId=$(echo "$response" | jq -r '.workflows | .[] | select(.path | contains("release-pc.yml")) | .id')
pcId=$(echo "$response" | jq -r '.workflows | .[] | select(.path | contains("release-pc.yml")) | .id')
dockerId=$(echo "$response" | jq -r '.workflows | .[] | select(.path | contains("release-docker.yml")) | .id')
iosId=$(echo "$response" | jq -r '.workflows | .[] | select(.path | contains("release-ios.yml")) | .id')
curl -X POST -H "Accept: application/vnd.github.v3+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/workflows/${androidId}/dispatches" -d "{\"ref\": \"main\", \"inputs\": {\"version\": \"${{ steps.version.outputs.release_version }}\", \"packageManager\": \"${{ steps.version.outputs.package_manager }}\"}}"
curl -X POST -H "Accept: application/vnd.github.v3+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/workflows/${pcId}/dispatches" -d "{\"ref\": \"main\", \"inputs\": {\"version\": \"${{ steps.version.outputs.release_version }}\", \"packageManager\": \"${{ steps.version.outputs.package_manager }}\"}}"
curl -X POST -H "Accept: application/vnd.github.v3+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/workflows/${dockerId}/dispatches" -d "{\"ref\": \"main\", \"inputs\": {\"version\": \"${{ steps.version.outputs.release_version }}\" }}"
curl -X POST -H "Accept: application/vnd.github.v3+json" -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" "https://api.github.com/repos/${GITHUB_REPOSITORY}/actions/workflows/${iosId}/dispatches" -d "{\"ref\": \"main\", \"inputs\": {\"version\": \"${{ steps.version.outputs.release_version }}\", \"packageManager\": \"${{ steps.version.outputs.package_manager }}\"}}"