release-cron #58
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }}\"}}" |