fix(release): 修复一键包启动脚本 #30
Workflow file for this run
This file contains hidden or 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: CI | |
| on: | |
| pull_request: | |
| push: | |
| branches: | |
| - main | |
| - master | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| inputs: | |
| publishImage: | |
| description: "发布 Docker 镜像到 GHCR" | |
| required: true | |
| type: boolean | |
| default: false | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| check: | |
| name: Check | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up JDK | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: "21" | |
| - name: Set up Gradle | |
| uses: gradle/actions/setup-gradle@v4 | |
| - name: Make Gradle wrapper executable | |
| run: chmod +x ./gradlew | |
| - name: Run tests and build application jar | |
| run: ./gradlew --no-daemon test fatJar | |
| - name: Upload application jar | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: dynamic-bot | |
| path: build/libs/*-all.jar | |
| if-no-files-found: error | |
| - name: Upload test reports | |
| if: failure() | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: test-reports | |
| path: build/reports/tests/ | |
| docker: | |
| name: Docker | |
| runs-on: ubuntu-latest | |
| needs: check | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Check tag matches project version | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| shell: bash | |
| run: | | |
| tag_version="${GITHUB_REF_NAME#v}" | |
| project_version="$(sed -nE 's/^version[[:space:]]*=[[:space:]]*"([^"]+)".*/\1/p' build.gradle.kts | head -n 1)" | |
| if [[ -z "$project_version" ]]; then | |
| echo "Cannot find project version in build.gradle.kts" | |
| exit 1 | |
| fi | |
| if [[ "$tag_version" != "$project_version" ]]; then | |
| echo "Tag version $tag_version does not match project version $project_version" | |
| exit 1 | |
| fi | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Log in to GHCR | |
| if: startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch' && inputs.publishImage == true) | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Extract Docker metadata | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ghcr.io/colter23/dynamic-bot | |
| tags: | | |
| type=ref,event=branch | |
| type=ref,event=pr | |
| type=semver,pattern={{version}} | |
| type=semver,pattern={{major}}.{{minor}} | |
| type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }} | |
| - name: Build Docker image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| push: ${{ startsWith(github.ref, 'refs/tags/v') || (github.event_name == 'workflow_dispatch' && inputs.publishImage == true) }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max | |
| release: | |
| name: Release | |
| runs-on: ubuntu-latest | |
| needs: | |
| - check | |
| - docker | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Install release packaging tools | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y zip unzip | |
| - name: Make release scripts executable | |
| run: chmod +x ./scripts/*.sh | |
| - name: Download application jar | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: dynamic-bot | |
| path: release | |
| - name: Check tag matches project version | |
| shell: bash | |
| run: | | |
| tag_version="${GITHUB_REF_NAME#v}" | |
| project_version="$(sed -nE 's/^version[[:space:]]*=[[:space:]]*"([^"]+)".*/\1/p' build.gradle.kts | head -n 1)" | |
| if [[ -z "$project_version" ]]; then | |
| echo "Cannot find project version in build.gradle.kts" | |
| exit 1 | |
| fi | |
| if [[ "$tag_version" != "$project_version" ]]; then | |
| echo "Tag version $tag_version does not match project version $project_version" | |
| exit 1 | |
| fi | |
| - name: Prepare one-click packages | |
| shell: bash | |
| run: | | |
| tag_version="${GITHUB_REF_NAME#v}" | |
| jar_file="$(ls release/*-all.jar | head -n 1)" | |
| ./scripts/package-release.sh "$tag_version" "$jar_file" release | |
| - name: Prepare official plugin package | |
| shell: bash | |
| run: | | |
| tag_version="${GITHUB_REF_NAME#v}" | |
| ./scripts/package-official-plugins.sh "$tag_version" packaging/official-plugins.lock.json release | |
| - name: Generate SHA-256 checksums | |
| shell: bash | |
| run: | | |
| cd release | |
| shopt -s nullglob | |
| files=(*-all.jar *.zip *.tar.gz) | |
| if [[ ${#files[@]} -eq 0 ]]; then | |
| echo "No release artifacts found" | |
| exit 1 | |
| fi | |
| sha256sum "${files[@]}" > SHA256SUMS.txt | |
| for file in "${files[@]}"; do | |
| sha256sum "$file" > "$file.sha256" | |
| done | |
| - name: Prepare release body | |
| shell: bash | |
| run: | | |
| image_version="${GITHUB_REF_NAME#v}" | |
| cat > release/release-body.md <<EOF | |
| 一键启动包: | |
| - \`dynamic-bot-v${image_version}-windows-x64-jre.zip\`:Windows x64,内置 Java 21。 | |
| - \`dynamic-bot-v${image_version}-linux-x64-jre.tar.gz\`:Linux x64,内置 Java 21。 | |
| - \`dynamic-bot-v${image_version}-windows-x64.zip\`:Windows x64,不带 JRE,需要 Java 17+。 | |
| - \`dynamic-bot-v${image_version}-linux-x64.tar.gz\`:Linux x64,不带 JRE,需要 Java 17+。 | |
| 官方插件合集: | |
| - \`dynamic-bot-v${image_version}-official-plugins.zip\`:包含本版本推荐搭配的 Bilibili、OneBot 和微博官方插件。 | |
| Docker 镜像: | |
| - \`ghcr.io/colter23/dynamic-bot:${image_version}\` | |
| - \`ghcr.io/colter23/dynamic-bot:latest\` | |
| EOF | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| name: dynamic-bot ${{ github.ref_name }} | |
| body_path: release/release-body.md | |
| files: | | |
| release/*-all.jar | |
| release/*.zip | |
| release/*.tar.gz | |
| release/*.sha256 | |
| release/SHA256SUMS.txt | |
| fail_on_unmatched_files: true | |
| generate_release_notes: true |