!9 chore: replace repository contents with current project #1
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: Publish Release | |
| on: | |
| push: | |
| branches: | |
| - main | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| inputs: | |
| tag_name: | |
| description: "Release tag, for example v2026.04.29-dc1c633" | |
| required: true | |
| type: string | |
| prerelease: | |
| description: "Mark this release as a prerelease" | |
| required: false | |
| default: false | |
| type: boolean | |
| permissions: | |
| contents: write | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Java | |
| uses: actions/setup-java@v4 | |
| with: | |
| distribution: temurin | |
| java-version: "17" | |
| cache: maven | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| cache: npm | |
| cache-dependency-path: web/package-lock.json | |
| - name: Resolve release tag | |
| id: release | |
| shell: bash | |
| run: | | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| RELEASE_TAG="${{ inputs.tag_name }}" | |
| elif [ "${{ github.ref_type }}" = "tag" ]; then | |
| RELEASE_TAG="${{ github.ref_name }}" | |
| else | |
| RELEASE_DATE="$(TZ=Asia/Shanghai date +%Y.%m.%d)" | |
| SHORT_SHA="${GITHUB_SHA::7}" | |
| RELEASE_TAG="v${RELEASE_DATE}-${SHORT_SHA}" | |
| fi | |
| if [[ ! "$RELEASE_TAG" =~ ^v[0-9]{4}\.[0-9]{2}\.[0-9]{2}-[0-9A-Za-z]{7,}$ ]]; then | |
| echo "Release tag must look like v2026.04.29-dc1c633, got: $RELEASE_TAG" | |
| exit 1 | |
| fi | |
| echo "tag=$RELEASE_TAG" >> "$GITHUB_OUTPUT" | |
| - name: Create tag for main push | |
| if: github.event_name == 'push' && github.ref_type == 'branch' && github.ref_name == 'main' | |
| shell: bash | |
| run: | | |
| RELEASE_TAG="${{ steps.release.outputs.tag }}" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| if git rev-parse -q --verify "refs/tags/$RELEASE_TAG" >/dev/null; then | |
| TAG_COMMIT="$(git rev-list -n 1 "$RELEASE_TAG")" | |
| if [ "$TAG_COMMIT" != "$GITHUB_SHA" ]; then | |
| echo "Tag $RELEASE_TAG already exists on $TAG_COMMIT, current commit is $GITHUB_SHA" | |
| exit 1 | |
| fi | |
| echo "Tag $RELEASE_TAG already exists on this commit" | |
| else | |
| git tag -a "$RELEASE_TAG" "$GITHUB_SHA" -m "Release $RELEASE_TAG" | |
| git push origin "refs/tags/$RELEASE_TAG" | |
| fi | |
| - name: Build release artifact | |
| run: mvn -B -DskipTests package | |
| - name: Prepare release files | |
| id: artifact | |
| shell: bash | |
| run: | | |
| VERSION="$(mvn -B -q -DforceStdout help:evaluate "-Dexpression=project.version")" | |
| JAR_PATH="$(find target -maxdepth 1 -type f -name "solon-claw-${VERSION}.jar" ! -name 'original-*' -print -quit)" | |
| if [ -z "$JAR_PATH" ]; then | |
| JAR_PATH="$(find target -maxdepth 1 -type f -name 'solon-claw-*.jar' ! -name 'original-*' -print -quit)" | |
| fi | |
| if [ -z "$JAR_PATH" ] || [ ! -f "$JAR_PATH" ]; then | |
| echo "Release jar not found" | |
| find target -maxdepth 1 -type f -print | |
| exit 1 | |
| fi | |
| mkdir -p dist | |
| RELEASE_JAR="dist/solon-claw-${VERSION}.jar" | |
| cp "$JAR_PATH" "$RELEASE_JAR" | |
| (cd dist && sha256sum "$(basename "$RELEASE_JAR")" > SHA256SUMS) | |
| cat > dist/release-notes.md <<EOF | |
| ## solon-claw ${{ steps.release.outputs.tag }} | |
| 本次发布包含可直接通过 \`java -jar\` 运行的完整 shaded jar。 | |
| ### 下载内容 | |
| - \`solon-claw-${VERSION}.jar\`:完整运行包,包含后端依赖与 Dashboard 静态资源。 | |
| - \`SHA256SUMS\`:发布包校验文件。 | |
| ### 快速运行 | |
| \`\`\`bash | |
| java -jar solon-claw-${VERSION}.jar | |
| \`\`\` | |
| 服务默认监听 \`http://127.0.0.1:8080\`,运行数据会写入当前目录的 \`runtime/\`。 | |
| EOF | |
| echo "jar_path=$RELEASE_JAR" >> "$GITHUB_OUTPUT" | |
| echo "sha_path=dist/SHA256SUMS" >> "$GITHUB_OUTPUT" | |
| echo "body_path=dist/release-notes.md" >> "$GITHUB_OUTPUT" | |
| - name: Upload workflow artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: solon-claw-release | |
| path: | | |
| ${{ steps.artifact.outputs.jar_path }} | |
| ${{ steps.artifact.outputs.sha_path }} | |
| if-no-files-found: error | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.release.outputs.tag }} | |
| target_commitish: ${{ github.sha }} | |
| name: solon-claw ${{ steps.release.outputs.tag }} | |
| body_path: ${{ steps.artifact.outputs.body_path }} | |
| generate_release_notes: true | |
| prerelease: ${{ github.event_name == 'workflow_dispatch' && inputs.prerelease || false }} | |
| fail_on_unmatched_files: true | |
| files: | | |
| ${{ steps.artifact.outputs.jar_path }} | |
| ${{ steps.artifact.outputs.sha_path }} |