Skip to content

feat: 搜索推荐词逻辑抽象为 SearchHintViewModel,FragmentSearch 和 SearchActivity 共用 #972

feat: 搜索推荐词逻辑抽象为 SearchHintViewModel,FragmentSearch 和 SearchActivity 共用

feat: 搜索推荐词逻辑抽象为 SearchHintViewModel,FragmentSearch 和 SearchActivity 共用 #972

Workflow file for this run

name: CI
on:
push:
branches:
- master
- classic
tags:
- v*.*.*
pull_request:
branches:
- master
- classic
paths-ignore:
- '**.md'
- '**.txt'
- 'renovate.json'
- '.editorconfig'
- '.gitignore'
- '.github/**'
- '.idea/**'
- '!.github/workflows/**'
workflow_dispatch:
env:
ORIGINAL_PROJECT: "CeuiLiSA/Pixiv-Shaft"
GRADLE_OPTS: "-Dorg.gradle.jvmargs=-Xmx4g"
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
name: Build apk
runs-on: ubuntu-24.04
steps:
- name: Clone repo
uses: actions/checkout@v4
with:
submodules: 'true'
fetch-depth: 0
- name: Set up JDK 21
uses: actions/setup-java@v4.2.2
with:
java-version: '21'
distribution: 'adopt'
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Detect branch
if: github.ref_type == 'branch'
run: |
BRANCH_NAME=${GITHUB_REF#refs/heads/}
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
if [ "$BRANCH_NAME" = "master" ]; then
echo "APK_SUFFIX=master" >> $GITHUB_ENV
elif [ "$BRANCH_NAME" = "classic" ]; then
echo "APK_SUFFIX=classic" >> $GITHUB_ENV
fi
- name: Build debug apk
if: github.ref_type == 'branch'
run: ./gradlew assembleGithubDebug
- name: Upload debug artifact
if: github.ref_type == 'branch'
uses: actions/upload-artifact@v4
with:
name: apk-debug-${{ env.APK_SUFFIX }}
path: app/build/outputs/apk/github/debug
- name: Get tag name
if: startsWith(github.ref, 'refs/tags/') && github.repository == env.ORIGINAL_PROJECT
run: |
set -x
version_tag=${GITHUB_REF/refs\/tags\//}
version_tag_short=`echo $version_tag | awk 'NR==1,/v/{sub(/v/, "");print}'`
echo "VERSION_TAG=$version_tag" >> $GITHUB_ENV
echo "VERSION_TAG_SHORT=$version_tag_short" >> $GITHUB_ENV
- name: Extract tag message before checkout
if: startsWith(github.ref, 'refs/tags/') && github.repository == env.ORIGINAL_PROJECT
run: |
TAG_MESSAGE=$(git cat-file tag "$VERSION_TAG" 2>/dev/null | sed '1,/^$/d' || echo "")
if [ -z "$TAG_MESSAGE" ]; then
TAG_MESSAGE="Release $VERSION_TAG"
fi
# Persist to file since env vars lose multiline
echo "$TAG_MESSAGE" > /tmp/tag_message.txt
- name: Detect and checkout correct branch
if: startsWith(github.ref, 'refs/tags/') && github.repository == env.ORIGINAL_PROJECT
run: |
# Auto-detect which branch this tagged commit belongs to
TAG_COMMIT=$(git rev-parse HEAD)
CLASSIC_CONTAINS=$(git merge-base --is-ancestor "$TAG_COMMIT" origin/classic && echo yes || echo no)
MASTER_CONTAINS=$(git merge-base --is-ancestor "$TAG_COMMIT" origin/master && echo yes || echo no)
if [ "$CLASSIC_CONTAINS" = "yes" ] && [ "$MASTER_CONTAINS" = "no" ]; then
TAG_BRANCH=classic
elif [ "$MASTER_CONTAINS" = "yes" ] && [ "$CLASSIC_CONTAINS" = "no" ]; then
TAG_BRANCH=master
elif [ "$CLASSIC_CONTAINS" = "yes" ] && [ "$MASTER_CONTAINS" = "yes" ]; then
# Commit exists on both branches, pick the one whose tip is closer
CLASSIC_DIST=$(git rev-list --count "$TAG_COMMIT"..origin/classic)
MASTER_DIST=$(git rev-list --count "$TAG_COMMIT"..origin/master)
if [ "$CLASSIC_DIST" -le "$MASTER_DIST" ]; then
TAG_BRANCH=classic
else
TAG_BRANCH=master
fi
else
TAG_BRANCH=master
fi
echo "TAG_BRANCH=$TAG_BRANCH" >> $GITHUB_ENV
echo "Detected branch: $TAG_BRANCH"
git checkout "origin/$TAG_BRANCH"
git submodule update --init --recursive
- name: Build release apk
if: startsWith(github.ref, 'refs/tags/') && github.repository == env.ORIGINAL_PROJECT
run: ./gradlew assembleGithubRelease --stacktrace
- name: Deal with release apk
if: startsWith(github.ref, 'refs/tags/') && github.repository == env.ORIGINAL_PROJECT
run: |
cp app/build/outputs/apk/github/release/app-github-release.apk app-release.apk
if [ "$TAG_BRANCH" = "classic" ]; then
APK_NAME="PixShaft_${VERSION_TAG_SHORT}_classic.apk"
else
APK_NAME="PixShaft_${VERSION_TAG_SHORT}.apk"
fi
cp app-release.apk "$APK_NAME"
echo "APK_NAME=$APK_NAME" >> $GITHUB_ENV
sha1=`sha1sum app-release.apk | awk '{ print toupper($1) }'`
sha256=`sha256sum app-release.apk | awk '{ print toupper($1) }'`
echo "APK_SHA1=$sha1" >> $GITHUB_ENV
echo "APK_SHA256=$sha256" >> $GITHUB_ENV
- name: Prepare release notes
if: startsWith(github.ref, 'refs/tags/') && github.repository == env.ORIGINAL_PROJECT
run: |
TAG_MESSAGE=$(cat /tmp/tag_message.txt)
# Write release notes with SHA checksums
{
echo "$TAG_MESSAGE"
echo ""
echo '```'
echo "SHA-1: $APK_SHA1"
echo "SHA-256: $APK_SHA256"
echo '```'
} > release_notes.md
- name: Draft release
if: startsWith(github.ref, 'refs/tags/') && github.repository == env.ORIGINAL_PROJECT
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.VERSION_TAG }}
name: ${{ env.VERSION_TAG }}
body_path: release_notes.md
files: |
${{ env.APK_NAME }}
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}