Merge pull request #4 from codcod/3-pull-requests-are-not-created-for… #8
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: | |
| - main | |
| pull_request: | |
| branches: | |
| - main | |
| permissions: | |
| contents: write | |
| packages: write | |
| pull-requests: read | |
| env: | |
| CARGO_TERM_COLOR: always | |
| RUST_BACKTRACE: 1 | |
| jobs: | |
| test: | |
| name: Run Tests | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Cache dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/bin/ | |
| ~/.cargo/registry/index/ | |
| ~/.cargo/registry/cache/ | |
| ~/.cargo/git/db/ | |
| target/ | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
| - name: Run tests | |
| run: cargo test --all-features | |
| - name: Run clippy | |
| run: cargo clippy --all-targets --all-features -- -D warnings | |
| - name: Check formatting | |
| run: cargo fmt --all -- --check | |
| semantic-version: | |
| name: Determine Version | |
| needs: test | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.version.outputs.version }} | |
| version_tag: ${{ steps.version.outputs.version_tag }} | |
| changed: ${{ steps.version.outputs.changed }} | |
| changelog: ${{ steps.version.outputs.changelog }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| - name: Semantic Version | |
| id: version | |
| uses: paulhatch/semantic-version@v5.4.0 | |
| with: | |
| tag_prefix: "v" | |
| major_pattern: "(MAJOR)" | |
| minor_pattern: "(MINOR)" | |
| version_format: "${major}.${minor}.${patch}" | |
| change_path: "src" | |
| namespace: "" | |
| bump_each_commit: false | |
| search_commit_body: true | |
| user_format_type: "csv" | |
| enable_prerelease_mode: false | |
| create-release: | |
| name: Create Release | |
| runs-on: ubuntu-latest | |
| needs: semantic-version | |
| if: needs.semantic-version.outputs.changed == 'true' && github.event_name == 'push' | |
| outputs: | |
| upload_url: ${{ steps.create_release.outputs.upload_url }} | |
| version: ${{ needs.semantic-version.outputs.version }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| - name: Update Cargo.toml version | |
| run: | | |
| sed -i.bak 's/^version = ".*"/version = "${{ needs.semantic-version.outputs.version }}"/' Cargo.toml && rm Cargo.toml.bak | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| git add Cargo.toml | |
| git commit -m "chore: bump version to ${{ needs.semantic-version.outputs.version }}" || exit 0 | |
| - name: Create Release | |
| id: create_release | |
| uses: softprops/action-gh-release@v2 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: ${{ needs.semantic-version.outputs.version_tag }} | |
| name: Release ${{ needs.semantic-version.outputs.version }} | |
| draft: false | |
| prerelease: false | |
| generate_release_notes: true | |
| body: | | |
| ## Changes | |
| ${{ needs.semantic-version.outputs.changelog }} | |
| ## Installation | |
| ### Binary Downloads | |
| You can download pre-built binaries for your platform from the assets below. | |
| ### Cargo Install | |
| ```bash | |
| cargo install repos | |
| ``` | |
| ### From Source | |
| ```bash | |
| git clone https://github.com/${{ github.repository }}.git | |
| cd repos | |
| cargo build --release | |
| ``` | |
| build-release: | |
| name: Build Release Binary | |
| needs: [semantic-version, create-release] | |
| if: needs.semantic-version.outputs.changed == 'true' && github.event_name == 'push' | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| include: | |
| - os: ubuntu-latest | |
| target: x86_64-unknown-linux-gnu | |
| suffix: "" | |
| # - os: ubuntu-latest | |
| # target: x86_64-unknown-linux-musl | |
| # suffix: "" | |
| # - os: windows-latest | |
| # target: x86_64-pc-windows-msvc | |
| # suffix: ".exe" | |
| - os: macos-latest | |
| target: x86_64-apple-darwin | |
| suffix: "" | |
| - os: macos-latest | |
| target: aarch64-apple-darwin | |
| suffix: "" | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| - name: Update Cargo.toml version | |
| run: | | |
| sed -i.bak 's/^version = ".*"/version = "${{ needs.semantic-version.outputs.version }}"/' Cargo.toml && rm Cargo.toml.bak | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Install musl tools | |
| if: matrix.target == 'x86_64-unknown-linux-musl' | |
| run: sudo apt-get update && sudo apt-get install -y musl-tools | |
| - name: Cache dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/bin/ | |
| ~/.cargo/registry/index/ | |
| ~/.cargo/registry/cache/ | |
| ~/.cargo/git/db/ | |
| target/ | |
| key: ${{ runner.os }}-${{ matrix.target }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
| - name: Build for ${{ matrix.target }} | |
| run: | | |
| cargo build --release --target ${{ matrix.target }} | |
| if [[ "${{ matrix.target }}" == *"windows"* ]]; then | |
| mv target/${{ matrix.target }}/release/repos.exe repos-${{ matrix.target }}.exe | |
| else | |
| mv target/${{ matrix.target }}/release/repos repos-${{ matrix.target }} | |
| fi | |
| - name: Strip binary (Unix only) | |
| if: matrix.suffix == '' | |
| run: strip target/${{ matrix.target }}/release/repos${{ matrix.suffix }} | |
| - name: Create archive | |
| shell: bash | |
| run: | | |
| staging="repos-${{ needs.semantic-version.outputs.version }}-${{ matrix.target }}" | |
| mkdir -p "$staging" | |
| cp target/${{ matrix.target }}/release/repos${{ matrix.suffix }} "$staging/" | |
| cp README.md LICENSE* "$staging/" 2>/dev/null || true | |
| tar czf "$staging.tar.gz" "$staging" | |
| echo "ASSET=$staging.tar.gz" >> $GITHUB_ENV | |
| - name: Upload Release Asset | |
| uses: softprops/action-gh-release@v2 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: ${{ needs.semantic-version.outputs.version_tag }} | |
| files: ${{ env.ASSET }} | |
| publish-crate: | |
| name: Publish to crates.io | |
| needs: [semantic-version, create-release, build-release] | |
| runs-on: ubuntu-latest | |
| if: needs.semantic-version.outputs.changed == 'true' && github.event_name == 'push' && !contains(needs.semantic-version.outputs.version, 'alpha') && !contains(needs.semantic-version.outputs.version, 'beta') && !contains(needs.semantic-version.outputs.version, 'rc') | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v5 | |
| - name: Update Cargo.toml version | |
| run: | | |
| sed -i.bak 's/^version = ".*"/version = "${{ needs.semantic-version.outputs.version }}"/' Cargo.toml && rm Cargo.toml.bak | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Cache dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.cargo/bin/ | |
| ~/.cargo/registry/index/ | |
| ~/.cargo/registry/cache/ | |
| ~/.cargo/git/db/ | |
| target/ | |
| key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
| - name: Publish to crates.io | |
| run: cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }} | |
| # docker-release: | |
| # name: Build and Push Docker Image | |
| # needs: create-release | |
| # runs-on: ubuntu-latest | |
| # steps: | |
| # - name: Checkout code | |
| # uses: actions/checkout@v5 | |
| # - name: Set up Docker Buildx | |
| # uses: docker/setup-buildx-action@v3 | |
| # - name: Log in to Docker Hub | |
| # uses: docker/login-action@v3 | |
| # with: | |
| # username: ${{ secrets.DOCKER_USERNAME }} | |
| # password: ${{ secrets.DOCKER_PASSWORD }} | |
| # - name: Extract metadata | |
| # id: meta | |
| # uses: docker/metadata-action@v5 | |
| # with: | |
| # images: ${{ secrets.DOCKER_USERNAME }}/repos | |
| # tags: | | |
| # type=ref,event=tag | |
| # type=semver,pattern={{version}} | |
| # type=semver,pattern={{major}}.{{minor}} | |
| # type=semver,pattern={{major}} | |
| # - name: Build and push Docker image | |
| # uses: docker/build-push-action@v5 | |
| # with: | |
| # context: . | |
| # platforms: linux/amd64,linux/arm64 | |
| # push: true | |
| # tags: ${{ steps.meta.outputs.tags }} | |
| # labels: ${{ steps.meta.outputs.labels }} | |
| # cache-from: type=gha | |
| # cache-to: type=gha,mode=max |