feat(git-msg): add dual license support and rename README_zh.md to RE… #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: Release & Publish | |
| on: | |
| push: | |
| branches: [ master, main ] | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| jobs: | |
| check-version: | |
| name: Check Version & Create Tag | |
| runs-on: ubuntu-latest | |
| outputs: | |
| is_new_version: ${{ steps.check.outputs.is_new_version }} | |
| version: ${{ steps.check.outputs.version }} | |
| tag: ${{ steps.check.outputs.tag }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Extract Cargo.toml version & check tag | |
| id: check | |
| run: | | |
| VERSION=$(grep -m1 '^version =' Cargo.toml | cut -d '"' -f 2) | |
| TAG="v$VERSION" | |
| echo "Detected version: $VERSION" | |
| echo "Expected tag: $TAG" | |
| if git rev-parse "$TAG" >/dev/null 2>&1; then | |
| echo "Tag $TAG already exists. Skipping release." | |
| echo "is_new_version=false" >> $GITHUB_OUTPUT | |
| else | |
| echo "New version detected: $VERSION" | |
| echo "is_new_version=true" >> $GITHUB_OUTPUT | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "tag=$TAG" >> $GITHUB_OUTPUT | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git tag -a "$TAG" -m "Release $TAG" | |
| git push origin "$TAG" | |
| fi | |
| publish-crates: | |
| name: Publish to crates.io | |
| needs: check-version | |
| if: needs.check-version.outputs.is_new_version == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Publish to crates.io | |
| run: cargo publish --allow-dirty | |
| env: | |
| CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
| create-github-release: | |
| name: Build & Release Binary for ${{ matrix.target }} | |
| needs: check-version | |
| if: needs.check-version.outputs.is_new_version == 'true' | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| target: x86_64-unknown-linux-gnu | |
| binary_name: git-msg | |
| asset_ext: tar.gz | |
| - os: windows-latest | |
| target: x86_64-pc-windows-msvc | |
| binary_name: git-msg.exe | |
| asset_ext: zip | |
| - os: macos-latest | |
| target: x86_64-apple-darwin | |
| binary_name: git-msg | |
| asset_ext: tar.gz | |
| - os: macos-latest | |
| target: aarch64-apple-darwin | |
| binary_name: git-msg | |
| asset_ext: tar.gz | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Build Release Binary | |
| run: cargo build --release --target ${{ matrix.target }} | |
| - name: Package Binary (Unix) | |
| if: matrix.os != 'windows-latest' | |
| run: | | |
| cd target/${{ matrix.target }}/release | |
| tar -czvf "../../../git-msg-${{ needs.check-version.outputs.tag }}-${{ matrix.target }}.tar.gz" "${{ matrix.binary_name }}" | |
| cd ../../.. | |
| - name: Package Binary (Windows) | |
| if: matrix.os == 'windows-latest' | |
| shell: pwsh | |
| run: | | |
| Compress-Archive -Path "target/${{ matrix.target }}/release/${{ matrix.binary_name }}" -DestinationPath "git-msg-${{ needs.check-version.outputs.tag }}-${{ matrix.target }}.zip" | |
| - name: Upload Binary to GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ needs.check-version.outputs.tag }} | |
| name: Release ${{ needs.check-version.outputs.tag }} | |
| files: git-msg-${{ needs.check-version.outputs.tag }}-${{ matrix.target }}.${{ matrix.asset_ext }} | |
| generate_release_notes: true |