Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add branch's base commit check #92

Merged
merged 3 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 76 additions & 0 deletions .github/commit_checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
"""
:file: commit_checks.py
:author: Paulo Santos ([email protected])
:brief: Realiza a verificação do histórico de commits.
:version: 0.1
:date: 29-04-2024

:copyright: Copyright (c) 2024
"""

import argparse
import subprocess
import sys


def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("-s", "--srcb", metavar="sbranch", help="Source branch to compare.")
parser.add_argument("-t", "--tgtb", metavar="tbranch", help="Target branch to compare.",
default="origin/main")

source_branch = str(parser.parse_args().srcb)
target_branch = str(parser.parse_args().tgtb)

if source_branch == "None":
print("\nSource branch is empty.")
return -1

invocation = f"git rev-list --count --left-right {target_branch}...{source_branch}"

try:
out = subprocess.check_output(invocation, shell=True)
behind, ahead = [int(dist) for dist in out.decode("utf-8").rsplit("\t", maxsplit=1)]
except Exception as e:
print(f"\nError to check the history: {e}")
return -1

if behind > 0:
print(f"\nThere are {behind} commits to be included in PR using rebase to main.\n")

return 1

if ahead > COMMIT_LIMIT:
print(f"\nThere are {ahead} commits to be added, divide PR to have less than {COMMIT_LIMIT + 1} commits.")

return 1

print(f"\nHistory is updated. ({ahead} commits ahead)")

invocation = f"git describe --all --first-parent {source_branch}~1 --abbrev=0"

try:
out = subprocess.check_output(invocation, shell=True)
parent_head = out.decode("utf-8").split("/")[-1].strip()
except Exception as e:
print(f"\nError to check the history: {e}")

return -1

if parent_head != "main":
print(
f"\nThe branch has its origin on `{parent_head}`, resolve `{parent_head}` first. (the branch must have "
f"origin on main)")

return 1

print("\nThe branch has its origin on main.")

return 0


if __name__ == "__main__":
COMMIT_LIMIT = 15
check_status = main()

sys.exit(check_status)
57 changes: 57 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: build

on:
pull_request:
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always

jobs:
build-ubuntu:
name: Check on Ubuntu
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: clippy
override: true

- name: Install libudev-sys
run: |
sudo apt-get install -y libudev-dev

- name: Build
run: |
cargo +nightly build --release --verbose

build-windows:
name: Check on Windows
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: clippy
override: true
- name: Build
run: |
cargo +nightly build --release --verbose

build-macos:
name: Check on MacOS
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
toolchain: nightly
components: clippy
override: true

- name: Build
run: |
cargo +nightly build --release --verbose
20 changes: 20 additions & 0 deletions .github/workflows/commit-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: commit-checks

on:
pull_request:
branches: [ "main" ]

jobs:
commit-check:
name: Check the branch base commit
runs-on: ubuntu-latest
steps:
- name: Checkout para a branch a ser testada.
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0

- name: Verifica os commits temporal e posicionalmente.
run: |
python ./.github/commit_checks.py -s origin/"${{github.head_ref}}"
50 changes: 0 additions & 50 deletions .github/workflows/rust.yml

This file was deleted.

Loading