Skip to content

Commit

Permalink
ci: make the commit lint job a reusable action
Browse files Browse the repository at this point in the history
  • Loading branch information
milinddethe15 authored and metaclips committed Oct 10, 2023
1 parent 656f03e commit 82cbd5b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 35 deletions.
41 changes: 41 additions & 0 deletions .github/actions/lint_workflow/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: 'Lint Commits'
runs:
using: 'composite'
steps:
- name: Checkout
if: github.event_name != 'pull_request'
uses: actions/checkout@$CHECKOUT_VERSION
with:
fetch-depth: 0 # checkout full tree

- name: Checkout (Pull Request)
if: github.event_name == 'pull_request'
uses: actions/checkout@$CHECKOUT_VERSION
with:
fetch-depth: 0 # checkout full tree
ref: ${{ github.event.pull_request.head.sha }}

- name: Get commit information from Github (Pull Request)
if: github.event_name == 'pull_request'
run: gh api repos/${REPO_NAME}/pulls/${{ github.event.number }}/commits > commits.json
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Set FIRST_COMMIT To Begin Linting (Pull Request)
if: github.event_name == 'pull_request'
run: |
pull_request_commits_length=$(cat commits.json | jq '. | length')
echo "Number of commits in pull requests are $pull_request_commits_length"
echo "FIRST_COMMIT=HEAD~${pull_request_commits_length}" >> $GITHUB_ENV
- name: Check no merge commits
run: |
merge_commit_count=$(git rev-list --no-walk --count --merges $FIRST_COMMIT..HEAD)
if [ "$merge_commit_count" != "0" ]; then
echo "
Our develop branch follows a linear history and cannot have merge commits.
Please rebase to develop.
" && exit 1
fi
39 changes: 4 additions & 35 deletions .github/workflows/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,12 @@ jobs:
env:
FIRST_COMMIT: 2fd0d36fe6ae0c2d527368683ec3a6352617b381
CONTRIBUTORS_CSV_PATH: .github/CONTRIBUTORS.csv
CHECKOUT_VERSION: 8ade135a41bc03ea155e62e844d188df1ea18608
REPO_NAME: build-trust/ockam

steps:
- name: Checkout
if: github.event_name != 'pull_request'
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
with:
fetch-depth: 0 # checkout full tree

- name: Checkout (Pull Request)
if: github.event_name == 'pull_request'
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608
with:
fetch-depth: 0 # checkout full tree
ref: ${{ github.event.pull_request.head.sha }}

- name: Get commit information from Github (Pull Request)
if: github.event_name == 'pull_request'
run: gh api repos/build-trust/ockam/pulls/${{ github.event.number }}/commits > commits.json
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Set FIRST_COMMIT To Begin Linting (Pull Request)
if: github.event_name == 'pull_request'
run: |
pull_request_commits_length=$(cat commits.json | jq '. | length')
echo "Number of commits in pull requests are $pull_request_commits_length"
echo "FIRST_COMMIT=HEAD~${pull_request_commits_length}" >> $GITHUB_ENV
- name: Run Composite Action
uses: ./.github/actions/lint_workflow/action.yml

- name: Check FIRST_COMMIT is ancestor of HEAD
run: |
Expand All @@ -78,16 +57,6 @@ jobs:
https://github.com/build-trust/ockam/tree/develop
" && exit 1)
- name: Check no merge commits
run: |
merge_commit_count=$(git rev-list --no-walk --count --merges $FIRST_COMMIT..HEAD)
if [ "$merge_commit_count" != "0" ]; then
echo "
Our develop branch follows a linear history and cannot have merge commits.
Please rebase to develop.
" && exit 1
fi
- name: Install Commitlint
run: npm install --location=global @commitlint/[email protected] # TODO: move to ockam-builder docker image.

Expand Down

0 comments on commit 82cbd5b

Please sign in to comment.