chore(release): 准备 0.0.6 发布 #27
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: Download application jar | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: dynamic-bot | |
| path: release | |
| - name: Generate SHA-256 checksum | |
| shell: bash | |
| run: | | |
| cd release | |
| jar_file="$(ls *-all.jar)" | |
| sha256sum "$jar_file" > "$jar_file.sha256" | |
| - 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 release body | |
| shell: bash | |
| run: | | |
| image_version="${GITHUB_REF_NAME#v}" | |
| cat > release/release-body.md <<EOF | |
| 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/*-all.jar.sha256 | |
| fail_on_unmatched_files: true | |
| generate_release_notes: true |