Skip to content

Commit

Permalink
feat!: follow conventional commits and setup automated releases (#48)
Browse files Browse the repository at this point in the history
Closes #38 and #43.

With bors configured in this repository the flow is a bit different, but I think this should be a good setup to allow automating releases. Instead of requiring commit messages to follow the Conventional Commits specification, we just require the PR title to follow it, since that is what ends up being the commit message of the squash merge commit.

Overlaps with #47 so closing that one.
  • Loading branch information
mbrobbel committed Jan 13, 2023
1 parent 2747477 commit 34d76d9
Show file tree
Hide file tree
Showing 15 changed files with 295 additions and 38 deletions.
17 changes: 11 additions & 6 deletions .github/bors.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
# SPDX-License-Identifier: Apache-2.0
status = [
"Check (default)",
"Check (pbjson)",
"Check (protoc)",
"Check (serde)",
"Test (default)",
"Test (pbjson)",
"Test (serde)",
"Rustfmt",
"Clippy (default)",
"Clippy (pbjson)",
"Clippy (serde)",
"Conventional Commits",
"Formatting",
"Rustdoc",
"Rustfmt",
"SPDX License Header",
"Test (default)",
"Test (pbjson)",
"Test (serde)",
]
delete_merged_branches = true
timeout_sec = 600
delete-merged-branches = true
timeout-sec = 600
use-squash-merge = true
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
# SPDX-License-Identifier: Apache-2.0

version: 2
updates:
- package-ecosystem: "cargo"
directory: "/"
schedule:
interval: "daily"
rebase-strategy: "disabled"
commit-message:
prefix: "chore(deps,cargo)"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
commit-message:
prefix: "chore(deps,github-actions)"

- package-ecosystem: "gitsubmodule"
directory: "/"
Expand All @@ -19,3 +25,5 @@ updates:
interval: "weekly"
day: "sunday"
time: "06:00"
commit-message:
prefix: "chore(deps)!"
24 changes: 24 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SPDX-License-Identifier: Apache-2.0

name: Check

on: [push, pull_request]

jobs:
license:
name: SPDX License Header
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: enarx/spdx@master
with:
licenses: Apache-2.0

formatting:
name: Formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
- run: npm install prettier prettier-plugin-toml
- run: npx prettier --check --no-config .
2 changes: 2 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# SPDX-License-Identifier: Apache-2.0

name: Docs

on: [push, pull_request]
Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# SPDX-License-Identifier: Apache-2.0

name: Merge

on:
push:
branches:
- trying # always pass on trying because commit message is not configurable
- staging

jobs:
conventional-commits:
name: Conventional Commits
runs-on: ubuntu-latest
steps:
- if: github.ref == 'refs/heads/staging'
uses: actions/checkout@v3
- if: github.ref == 'refs/heads/staging'
uses: actions/setup-node@v3
- if: github.ref == 'refs/heads/staging'
run: |
npm install @commitlint/config-conventional
echo "${{ github.event.head_commit.message }}" | npx commitlint --extends @commitlint/config-conventional
57 changes: 57 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# SPDX-License-Identifier: Apache-2.0

name: Pull Request

on:
pull_request_target:
types:
- opened
- reopened
- edited
- synchronize

permissions:
issues: write

jobs:
title:
name: Title
runs-on: ubuntu-latest
if: "!startsWith(github.event.pull_request.title, '[Merged by Bors] - ')"
steps:
- uses: actions/setup-node@v3
- run: npm install @commitlint/config-conventional
- id: commitlint
run: echo "${{ github.event.pull_request.title }}" | npx commitlint --extends @commitlint/config-conventional
- if: failure()
uses: actions/github-script@v6
with:
script: |
const message = `Substrait follows the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/) for release automation.
The PR title is used as the merge commit message.
Please update your PR title to match the specification.`
// Get list of current comments
const list_comments = github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
})
const comments = await github.paginate(list_comments)
// Check if this job already commented
for (const comment of comments) {
if (comment.body === message) {
return // Already commented
}
}
// Post the comment about Conventional Commits
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: message
})
core.setFailed('Invalid PR title')
39 changes: 39 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# SPDX-License-Identifier: Apache-2.0

name: Release

on:
push:
branches:
- main

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
submodules: recursive
- uses: dtolnay/rust-toolchain@stable
- run: cargo install cargo-smart-release --debug --locked
- uses: arduino/setup-protoc@v1
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- run: cargo check
- run: cargo changelog --execute substrait
- run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- env:
GH_TOKEN: ${{ github.token }}
CARGO_REGISTRY_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
run: |
cargo smart-release \
--allow-fully-generated-changelogs \
--execute \
--no-changelog-preview \
--allow-dirty \
--verbose \
substrait
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# SPDX-License-Identifier: Apache-2.0

name: Test

on: [push, pull_request]
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# SPDX-License-Identifier: Apache-2.0

/target
Cargo.lock

.idea

package.json
package-lock.json
node_modules/
2 changes: 2 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# SPDX-License-Identifier: Apache-2.0

[submodule "substrait"]
path = substrait
url = https://github.com/substrait-io/substrait
6 changes: 6 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# SPDX-License-Identifier: Apache-2.0

/target
CHANGELOG.md
LICENSE
substrait/
Empty file added CHANGELOG.md
Empty file.
112 changes: 112 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Contributing

All contributors and contributions are welcome! Please open an issue on GitHub if you have issues, questions or ideas.

## GitHub

### Pull requests

Substrait follows the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/) for Pull Request titles. This allows for automation of releases based on commit messages that are merged to the default branch.

The `Title` job of the [Pull Request](.github/workflow/pull-request.yml) workflow and the `Conventional Commits` job of the [Merge](.github/workflows/merge.yml) workflow check the Pull Request title and merge commit message.

### Dependabot

substrait-rs uses [Depedendabot](https://docs.github.com/en/code-security/dependabot) to update dependencies using the [dependabot.yml](.github/dependabot.yml) configuration file.

### Bors

substrait-rs uses [bors](https://bors.tech/) to merge Pull Requests to prevent breaking the default branch using the [bors.toml](.github/bors.toml) configuration file.

### Prettier

substrait-rs uses [Prettier](https://prettier.io/) to format non-Rust source files. The `Formatting` job in the [Check](.github/workflows/check.yml) workflow checks this. To format your files locally (requires [Node.js](https://nodejs.org/en/)):

```shell
npm install prettier prettier-plugin-toml --save-dev --save-exact
npx prettier --write --no-config .
```

## Governance

Please refer to the [Substrait Governance](https://substrait.io/governance/) page.

## Community

Please refer to the [Substrait Community](https://substrait.io/community/) page.

## License

All contributions should be licensed under [Apache License, Version 2.0](LICENSE).
All source files must have a valid SPDX license header. The `SPDX License Header` job in the [Check](.github/workflow/check.yml) workflow checks this.

Substrait requires all contributors to sign the [Contributor License Agreement (CLA)](https://cla-assistant.io/substrait-io/substrait). There is a GitHub app installed to help new contributors sign it.

## Development

### Requirements

- [Rust](https://rustup.rs)
- [protoc (>=3.15)](https://github.com/protocolbuffers/protobuf/releases)

In environments where no `protoc` is available the `protoc` feature can be enabled to build `protoc` from source:

```shell
cargo build --features protoc
```

### Substrait submodule

There is a git submodule for [Substrait](https://github.com/substrait-io/substrait) that must be cloned when building from source.

```shell
git clone --recurse-submodules [email protected]:substrait-io/substrait-rs.git
```

When the Substrait version is bumped make sure to update your local submodule.

```shell
git submodule update
```

Formatting, lints and tests are checked in the [Test](.github/workflows/test.yml) workflow.

### Docs

#### Rustdoc

The crate documentation is built with [rustdoc](https://doc.rust-lang.org/rustdoc/what-is-rustdoc.html):

```shell
cargo doc
```

Or to enable automatic feature information (requires a nightly toolchain):

```shell
cargo +nightly rustdoc -- --cfg docsrs
```

### Formatting

All Rust code is formatted using [rustfmt](https://github.com/rust-lang/rustfmt):

```shell
cargo fmt
```

### Linting

All Rust code passes [Clippy](https://github.com/rust-lang/rust-clippy) lints without warnings:

```shell
cargo clippy -- -Dwarnings
```

### Tests

To run tests and [documentation tests](https://doc.rust-lang.org/rustdoc/write-documentation/documentation-tests.html):

```shell
cargo test
```
29 changes: 0 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,3 @@ Rust crate for [Substrait](https://substrait.io/): Cross-Language Serialization

- [Docs (release)](https://docs.rs/substrait)
- [Docs (main)](https://substrait-io.github.io/substrait-rs/substrait/)

## Development

### Requirements

- [Rust](https://rustup.rs)
- [protoc (>=3.15)](https://github.com/protocolbuffers/protobuf/releases)

### Build & test

Clone this repository.

```shell
git clone [email protected]:substrait-io/substrait-rs.git
cd substrait-rs
```

Update submodules.

```shell
git submodule init
git submodule update
```

Build and test with Cargo.

```shell
cargo test
```
Loading

0 comments on commit 34d76d9

Please sign in to comment.