Skip to content

Commit

Permalink
chore: release with cron
Browse files Browse the repository at this point in the history
  • Loading branch information
xinshangshangxin committed Mar 26, 2024
1 parent 82c2818 commit 6eb8b0d
Show file tree
Hide file tree
Showing 7 changed files with 397 additions and 464 deletions.
86 changes: 0 additions & 86 deletions .github/workflows/dockerimage.yml

This file was deleted.

132 changes: 132 additions & 0 deletions .github/workflows/release-android.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
name: release-android

on:
workflow_dispatch:
inputs:
version:
description: "release version/tag"
required: true

jobs:
build:
runs-on: ${{ matrix.config.os }}
strategy:
matrix:
config:
- os: ubuntu-20.04
kernel_path: "../../../siyuan-android/app/libs/kernel.aar"

steps:
- uses: actions/checkout@v3
with:
path: ${{ github.workspace }}/siyuan-note/

- name: clone origin and apply patches
run: |
mkdir -p ${{ github.workspace }}/go
cd ${{ github.workspace }}/siyuan-note/
git clone --branch v${{ github.event.inputs.version }} --depth=1 https://github.com/siyuan-note/siyuan.git
cd siyuan
git apply ${{ github.workspace }}/siyuan-note/patches/siyuan/disable-update.patch
git apply ${{ github.workspace }}/siyuan-note/patches/siyuan/mock-vip-user.patch
git status
cd ..
git clone --branch v${{ github.event.inputs.version }} --depth=1 https://github.com/siyuan-note/siyuan-android.git
cd siyuan-android
git apply ${{ github.workspace }}/siyuan-note/patches/siyuan-android/debug-build.patch
mkdir -p app/src/main/assets/
mkdir -p app/libs/
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.22"

- name: Set up Node
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install Node pnpm
run: npm install -g pnpm
working-directory: ${{ github.workspace }}/siyuan-note/siyuan/app

- name: Install Node Dependencies
run: pnpm install --no-frozen-lockfile
working-directory: ${{ github.workspace }}/siyuan-note/siyuan/app

- name: Building UI
run: pnpm run build
working-directory: ${{ github.workspace }}/siyuan-note/siyuan/app

- name: Remove Build Directory
uses: JesseTG/[email protected]
with:
path: ${{ github.workspace }}/siyuan-note/siyuan/app/build

- name: gomobile
working-directory: ${{ github.workspace }}/go
run: |
go install golang.org/x/mobile/cmd/gomobile@latest
gomobile init
- name: Set up java
uses: actions/setup-java@v3
with:
distribution: "temurin"
java-version: "17"
cache: "gradle"

- name: Building Android Kernel
run: |
gomobile bind --tags fts5 -androidapi 21 -target='android/arm64' -ldflags '-s -w' -v -o "${{ matrix.config.kernel_path }}" ./
ls -la "${{ matrix.config.kernel_path }}"
working-directory: ${{ github.workspace }}/siyuan-note/siyuan/kernel/mobile
env:
GO111MODULE: on
CGO_ENABLED: 1

- name: android assets
working-directory: ${{ github.workspace }}/siyuan-note/siyuan/app/
run: |
zip -r ${{ github.workspace }}/siyuan-note/siyuan-android/app/src/main/assets/app.zip ./appearance ./guide ./stage ./changelogs
- name: Decode Keystore
id: decode_keystore
uses: timheuer/[email protected]
with:
fileName: "debug.jks"
fileDir: ${{ github.workspace }}/siyuan-note/siyuan-android/keystore
encodedString: ${{ secrets.KEYSTORE }}

- name: Building Android
working-directory: ${{ github.workspace }}/siyuan-note/siyuan-android
run: |
chmod 777 ./gradlew
./gradlew :app:assembleDebug
env:
KEYSTORE_PASSWORD: ${{ secrets.KEYSTORE_PASSWORD }}

- uses: joutvhu/get-release@v1
id: get_current_release
with:
tag_name: ${{ github.event.inputs.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload Android
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.get_current_release.outputs.upload_url }}
asset_name: siyuan-${{ github.event.inputs.version }}-android-arm64.apk
asset_path: ${{ github.workspace }}/siyuan-note/siyuan-android/app/build/outputs/apk/debug/app-debug.apk
asset_content_type: application/octet-stream
65 changes: 65 additions & 0 deletions .github/workflows/release-cron.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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
outputs:
version: ${{ steps.version.outputs.release_version }}
upload_url: ${{ steps.create_release.outputs.upload_url }}
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')
# 获取最新代码的版本
packageVersion=$(wget -qO- -t3 -T30 "https://raw.githubusercontent.com/siyuan-note/siyuan/master/app/package.json" | grep "version" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g')
# 设置输出
if [ "${releasedVersion}" = "${packageVersion}" ]; then
echo "release_version=0" >> $GITHUB_OUTPUT
else
echo "release_version=${packageVersion}" >> $GITHUB_OUTPUT
fi
echo "releasedVersion: ${releasedVersion}"
echo "packageVersion: ${packageVersion}"
- 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 }}\"}}"
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 }}\"}}"
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 }}\"}}"
70 changes: 70 additions & 0 deletions .github/workflows/release-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: release-docker

on:
workflow_dispatch:
inputs:
version:
description: "release version/tag"
required: true

jobs:
build:
name: build
runs-on: ubuntu-latest

permissions:
packages: write
contents: read

steps:
- name: Free Disk Space (Ubuntu)
uses: jlumbroso/free-disk-space@main
with:
# this might remove tools that are actually needed,
# if set to "true" but frees about 6 GB
tool-cache: false

# all of these default to true, but feel free to set to
# "false" if necessary for your workflow
android: true
dotnet: true
haskell: true
large-packages: true
docker-images: true
swap-storage: true

- uses: actions/checkout@v3
with:
path: ${{ github.workspace }}/siyuan-note/

- name: clone origin and apply patches
run: |
mkdir -p ${{ github.workspace }}/go
cd ${{ github.workspace }}/siyuan-note/
git clone --branch v${{ github.event.inputs.version }} --depth=1 https://github.com/siyuan-note/siyuan.git
cd siyuan
git apply ${{ github.workspace }}/siyuan-note/patches/siyuan/disable-update.patch
git apply ${{ github.workspace }}/siyuan-note/patches/siyuan/mock-vip-user.patch
git status
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2

- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_PWD }}

- name: Build the Docker image
working-directory: ${{ github.workspace }}/siyuan-note/siyuan
run: |
docker buildx build --push --platform linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v8 -t ${{ env.DOCKER_HUB_USER }}/siyuan:latest -t ${{ env.DOCKER_HUB_USER }}/siyuan:v${{ github.event.inputs.version }} .
env:
DOCKER_HUB_USER: ${{ secrets.DOCKER_HUB_USER }}
Loading

0 comments on commit 6eb8b0d

Please sign in to comment.