Merge pull request #15 from TebogoYungMercykay/feature_01 #27
This file contains 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: Branch Protection, Testing and Notification | |
on: | |
push: | |
branches: [ development, master ] | |
pull_request: | |
branches: [ development, master ] | |
jobs: | |
build_and_test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: install dependencies | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y libgtest-dev cmake | |
cd /usr/src/gtest | |
sudo cmake CMakeLists.txt | |
sudo make | |
cd /usr/src/googletest/googletest/lib | |
sudo cp *.a /usr/lib | |
- name: build | |
run: g++ -std=c++11 -o test/test test/test.cpp -lgtest -lpthread | |
- name: test | |
run: ./test/test | |
lint_and_format: | |
runs-on: ubuntu-latest | |
needs: build_and_test | |
steps: | |
- name: Check Out Code | |
uses: actions/checkout@v2 | |
with: | |
token: ${{ secrets.WACKDONALDS_TOKEN }} | |
- name: Install clang-tidy and clang-format | |
run: | | |
sudo apt-get update | |
sudo apt-get install -y clang-tidy clang-format | |
- name: Lint with clang-tidy (Readability checks only) | |
run: clang-tidy -p=build -header-filter=.* -checks=-*,readability-* src/*.cpp | |
- name: Format code with clang-format | |
run: clang-format -i -style=file src/*.cpp | |
- name: Set Git User Info | |
run: | | |
git config user.name "${{ secrets.GIT_USER }}" | |
git config user.email "${{ secrets.GIT_USER_EMAIL }}" | |
- name: Check for changes | |
id: changes | |
run: | | |
git diff --exit-code --quiet && echo "::set-output name=changed::false" || echo "::set-output name=changed::true" | |
- name: Add changes to staging area | |
run: git add -A | |
if: steps.changes.outputs.changed == 'true' | |
- name: Commit and Push Changes | |
run: | | |
git commit -am "Linter: Applied clang-format and clang-tidy Fixes" | |
git fetch origin ${{ github.head_ref }}:${{ github.head_ref }} | |
git rebase origin/${{ github.head_ref }} | |
git push origin HEAD:${{ github.head_ref }} | |
if: steps.changes.outputs.changed == 'true' | |
protect_and_notify: | |
if: github.event_name == 'pull_request' | |
needs: build_and_test | |
runs-on: ubuntu-latest | |
steps: | |
- name: Notify Contributors | |
uses: actions/github-script@v3 | |
with: | |
github-token: ${{secrets.WACKDONALDS_TOKEN}} | |
script: | | |
const issueNumber = context.issue.number; | |
const contributors = await github.repos.listContributors({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
}); | |
contributors.data.forEach(async (contributor) => { | |
await github.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issueNumber, | |
body: `@${contributor.login} A new pull request has been created.`, | |
}); | |
}); |