From 04110fe69ea498d862e5332a099ef2f748f339e7 Mon Sep 17 00:00:00 2001 From: Xenira <1288524+Xenira@users.noreply.github.com> Date: Sun, 1 Dec 2024 22:53:55 +0100 Subject: [PATCH] ci(release): add release bot Refs: #340 --- .github/dependabot.yml | 7 ++++ .github/workflows/build.yml | 68 +++++++++++++++++++++++++++---- .github/workflows/release-plz.yml | 64 +++++++++++++++++++++++++++++ .release-plz.toml | 50 +++++++++++++++++++++++ README.md | 5 +++ crates/cli/Cargo.toml | 2 +- 6 files changed, 187 insertions(+), 9 deletions(-) create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/release-plz.yml create mode 100644 .release-plz.toml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..7ee8cf824 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + # Check for updates every Monday + schedule: + interval: "weekly" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7237b791b..ccae99e97 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -7,8 +7,66 @@ on: branches: - master pull_request: +env: + RUST_CACHE_PREFIX: "v0-rust" jobs: + lint: + name: Lint + runs-on: ubuntu-latest + env: + clang: "17" + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Check typos + uses: crate-ci/typos@master + - name: Validate commit messages + run: | + git show-ref + curl -sSfL https://github.com/convco/convco/releases/latest/download/convco-ubuntu.zip | zcat > convco + chmod +x convco + ./convco check refs/remotes/origin/master..HEAD + rm convco + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + env: + debug: true + - name: Setup Rust + uses: dtolnay/rust-toolchain@master + with: + components: rustfmt, clippy + toolchain: stable + - name: Cache cargo dependencies + uses: Swatinem/rust-cache@v2 + with: + # increment this manually to force cache eviction + prefix-key: ${{ env.RUST_CACHE_PREFIX }} + - name: Cache LLVM and Clang + id: cache-llvm + uses: actions/cache@v3 + with: + path: ${{ runner.temp }}/llvm-{{ env.clang }} + key: ubuntu-latest-llvm-${{ env.clang }} + - name: Setup LLVM & Clang + id: clang + uses: KyleMayes/install-llvm-action@v2 + with: + version: ${{ env.clang }} + directory: ${{ runner.temp }}/llvm-${{ env.clang }} + - name: Configure Clang + run: | + echo "LIBCLANG_PATH=${{ runner.temp }}/llvm-${{ env.clang }}/lib" >> $GITHUB_ENV + echo "LLVM_VERSION=${{ steps.clang.outputs.version }}" >> $GITHUB_ENV + echo "LLVM_CONFIG_PATH=${{ runner.temp }}/llvm-${{ env.clang }}/bin/llvm-config" >> $GITHUB_ENV + - name: Run rustfmt + run: cargo fmt --all -- --check + - name: Run clippy + run: cargo clippy --all -- -D warnings build: name: Build and Test runs-on: ${{ matrix.os }} @@ -59,7 +117,7 @@ jobs: # if: matrix.rust == 'stable' with: # increment this manually to force cache eviction - prefix-key: "v0-rust" + prefix-key: ${{ env.RUST_CACHE_PREFIX }} # LLVM & Clang - name: Cache LLVM and Clang id: cache-llvm @@ -89,15 +147,9 @@ jobs: env: EXT_PHP_RS_TEST: "" run: cargo build --release --features closure,anyhow --all - # Test & lint + # Test - name: Test inline examples run: cargo test --release --all --features closure,anyhow --no-fail-fast - - name: Run rustfmt - if: matrix.rust == 'stable' && matrix.os == 'ubuntu-latest' && matrix.php == '8.2' - run: cargo fmt --all -- --check - - name: Run clippy - if: matrix.rust == 'stable' && matrix.os == 'ubuntu-latest' && matrix.php == '8.2' - run: cargo clippy --all -- -D warnings # Docs - name: Run rustdoc if: matrix.rust == 'stable' && matrix.os == 'ubuntu-latest' && matrix.php == '8.2' diff --git a/.github/workflows/release-plz.yml b/.github/workflows/release-plz.yml new file mode 100644 index 000000000..1fd5cda3f --- /dev/null +++ b/.github/workflows/release-plz.yml @@ -0,0 +1,64 @@ +name: Release-plz + +permissions: + pull-requests: write + contents: write + +on: + workflow_run: + workflows: ["Build and Lint"] + branches: ["master"] + types: + - completed + +jobs: + release-plz-release: + name: Release-plz release + runs-on: ubuntu-latest + steps: + - name: Generate GitHub token + uses: actions/create-github-app-token@v1 + id: generate-token + with: + app-id: ${{ secrets.APP_ID }} + private-key: ${{ secrets.APP_PRIVATE_KEY }} + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + - name: Run release-plz + uses: release-plz/action@v0.5 + with: + command: release + env: + GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }} + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} + + release-plz-pr: + name: Release-plz PR + runs-on: ubuntu-latest + concurrency: + group: release-plz-${{ github.ref }} + cancel-in-progress: false + steps: + - name: Generate GitHub token + uses: actions/create-github-app-token@v1 + id: generate-token + with: + app-id: ${{ secrets.APP_ID }} + private-key: ${{ secrets.APP_PRIVATE_KEY }} + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + - name: Run release-plz + uses: release-plz/action@v0.5 + with: + command: release-pr + env: + GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }} + CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} diff --git a/.release-plz.toml b/.release-plz.toml new file mode 100644 index 000000000..9cfed95d3 --- /dev/null +++ b/.release-plz.toml @@ -0,0 +1,50 @@ +[workspace] +git_release_body = """ +{{ changelog }} +{% if remote.contributors %} +### Thanks to the contributors for this release: +{% for contributor in remote.contributors %} +* @{{ contributor.username }} +{% endfor %} +{% endif %} +""" + +[changelog] +header = "# Changelog" +body = """ +{%- macro username(commit) -%} + {% if commit.remote.username %} (by @{{ commit.remote.username }}){% endif -%} +{% endmacro -%} +{% macro commit_message(commit) %} + - {% if commit.scope %}*({{ commit.scope }})* {% endif %}\ + {% if commit.breaking %}[**breaking**] {% endif %}\ + {{ commit.message | upper_first }}\ + {{ self::username(commit=commit) }} \ + {%- if commit.links %} \ + {% for link in commit.links | unique(attribute="href") %}\ + [[{{link.text}}]({{link.href}})] \ + {% endfor %}\ + {% endif %} + {%- if commit.breaking and commit.breaking_description and not commit.breaking_description == commit.message%} + > {{ commit.breaking_description -}} + {% endif -%} +{% endmacro %} +## [{{ version | trim_start_matches(pat="v") }}]{%- if release_link -%}({{ release_link }}){% endif %} - {{ timestamp | date(format="%Y-%m-%d") -}} +{%- for group, commits in commits | group_by(attribute="group") %} + + ### {{ group | upper_first -}} + {% for commit in commits + | filter(attribute="scope") + | sort(attribute="scope") -%} + {{- self::commit_message(commit=commit) -}} + {% endfor -%} + {%- for commit in commits -%} + {% if not commit.scope -%} + {{- self::commit_message(commit=commit) -}} + {% endif -%} + {% endfor -%} +{% endfor %} +""" +link_parsers = [ + { pattern = "#(\\d+)", href = "https://github.com/davidcole1340/ext-php-rs/issues/$1" }, +] diff --git a/README.md b/README.md index edc274aa3..1c87b98c5 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,11 @@ Contributions welcome include: - Bug fixes and features. - Feature requests. +When contributing, please keep in mind the following: +- Create tests if possible. +- Update the documentation if necessary. +- Use [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/). We use these to automatically generate changelogs. + Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions. diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 004a1cbc6..0fea3b1ba 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -11,7 +11,7 @@ edition = "2018" categories = ["api-bindings", "command-line-interface"] [dependencies] -ext-php-rs = { version = ">=0.7.1", path = "../../" } +ext-php-rs = { version = "0.12.0", path = "../../" } clap = { version = "4.0", features = ["derive"] } anyhow = "1"