Merge pull request #3 from bordeux/hotfix/update-docs #2
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 | |
| on: | |
| push: | |
| branches: | |
| - master | |
| - main | |
| permissions: | |
| contents: write | |
| packages: write | |
| jobs: | |
| semantic-release: | |
| name: Semantic Release | |
| runs-on: ubuntu-latest | |
| outputs: | |
| new_release_published: ${{ steps.semantic.outputs.new_release_published }} | |
| new_release_version: ${{ steps.semantic.outputs.new_release_version }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Install semantic-release | |
| run: | | |
| npm install -g semantic-release@23 \ | |
| @semantic-release/git@10 \ | |
| @semantic-release/changelog@6 \ | |
| @semantic-release/exec@6 \ | |
| conventional-changelog-conventionalcommits@7 | |
| - name: Run semantic-release | |
| id: semantic | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: npx semantic-release | |
| build: | |
| name: Build ${{ matrix.target }} | |
| needs: semantic-release | |
| if: needs.semantic-release.outputs.new_release_published == 'true' | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| include: | |
| - target: x86_64-unknown-linux-gnu | |
| os: ubuntu-latest | |
| artifact_name: tmpltool | |
| asset_name: tmpltool-linux-x86_64 | |
| - target: x86_64-unknown-linux-musl | |
| os: ubuntu-latest | |
| artifact_name: tmpltool | |
| asset_name: tmpltool-linux-x86_64-musl | |
| - target: aarch64-unknown-linux-gnu | |
| os: ubuntu-latest | |
| artifact_name: tmpltool | |
| asset_name: tmpltool-linux-aarch64 | |
| - target: x86_64-apple-darwin | |
| os: macos-latest | |
| artifact_name: tmpltool | |
| asset_name: tmpltool-macos-x86_64 | |
| - target: aarch64-apple-darwin | |
| os: macos-latest | |
| artifact_name: tmpltool | |
| asset_name: tmpltool-macos-aarch64 | |
| - target: x86_64-pc-windows-msvc | |
| os: windows-latest | |
| artifact_name: tmpltool.exe | |
| asset_name: tmpltool-windows-x86_64.exe | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: v${{ needs.semantic-release.outputs.new_release_version }} | |
| - name: Setup Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Install cross (Linux ARM) | |
| if: matrix.target == 'aarch64-unknown-linux-gnu' | |
| run: cargo install cross --git https://github.com/cross-rs/cross | |
| - name: Install musl tools (Linux musl) | |
| if: matrix.target == 'x86_64-unknown-linux-musl' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y musl-tools | |
| - name: Cache cargo registry | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.cargo/registry | |
| key: ${{ runner.os }}-${{ matrix.target }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} | |
| - name: Cache cargo index | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.cargo/git | |
| key: ${{ runner.os }}-${{ matrix.target }}-cargo-git-${{ hashFiles('**/Cargo.lock') }} | |
| - name: Cache cargo build | |
| uses: actions/cache@v4 | |
| with: | |
| path: target | |
| key: ${{ runner.os }}-${{ matrix.target }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} | |
| - name: Build (cross) | |
| if: matrix.target == 'aarch64-unknown-linux-gnu' | |
| run: cross build --release --target ${{ matrix.target }} | |
| - name: Build (cargo) | |
| if: matrix.target != 'aarch64-unknown-linux-gnu' | |
| run: cargo build --release --target ${{ matrix.target }} | |
| - name: Strip binary (Linux/macOS) | |
| if: matrix.os != 'windows-latest' | |
| run: strip target/${{ matrix.target }}/release/${{ matrix.artifact_name }} || true | |
| - name: Create archive (Linux/macOS) | |
| if: matrix.os != 'windows-latest' | |
| run: | | |
| cd target/${{ matrix.target }}/release | |
| tar czf ${{ matrix.asset_name }}.tar.gz ${{ matrix.artifact_name }} | |
| mv ${{ matrix.asset_name }}.tar.gz ../../.. | |
| - name: Create archive (Windows) | |
| if: matrix.os == 'windows-latest' | |
| shell: pwsh | |
| run: | | |
| cd target/${{ matrix.target }}/release | |
| Compress-Archive -Path ${{ matrix.artifact_name }} -DestinationPath ../../../${{ matrix.asset_name }}.zip | |
| - name: Upload artifact (Linux/macOS) | |
| if: matrix.os != 'windows-latest' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.asset_name }} | |
| path: ${{ matrix.asset_name }}.tar.gz | |
| - name: Upload artifact (Windows) | |
| if: matrix.os == 'windows-latest' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.asset_name }} | |
| path: ${{ matrix.asset_name }}.zip | |
| upload-release-assets: | |
| name: Upload Release Assets | |
| needs: [semantic-release, build] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: Display structure | |
| run: ls -R artifacts | |
| - name: Upload release assets | |
| uses: softprops/action-gh-release@v1 | |
| with: | |
| tag_name: v${{ needs.semantic-release.outputs.new_release_version }} | |
| files: artifacts/**/* | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| docker: | |
| name: Build and Push Docker Image | |
| needs: [semantic-release, build] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: v${{ needs.semantic-release.outputs.new_release_version }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to GitHub Container Registry | |
| uses: docker/login-action@v3 | |
| with: | |
| registry: ghcr.io | |
| username: ${{ github.repository_owner }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Docker meta | |
| id: meta | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ghcr.io/${{ github.repository }} | |
| tags: | | |
| type=semver,pattern={{version}},value=${{ needs.semantic-release.outputs.new_release_version }} | |
| type=semver,pattern={{major}}.{{minor}},value=${{ needs.semantic-release.outputs.new_release_version }} | |
| type=semver,pattern={{major}},value=${{ needs.semantic-release.outputs.new_release_version }} | |
| type=raw,value=latest | |
| - name: Build and push | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| tags: ${{ steps.meta.outputs.tags }} | |
| labels: ${{ steps.meta.outputs.labels }} | |
| platforms: linux/amd64,linux/arm64 | |
| cache-from: type=gha | |
| cache-to: type=gha,mode=max |