add-workflow-approval (#146) #206
This file contains hidden or 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
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions | |
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | |
name: Python package | |
on: [push, pull_request] | |
jobs: | |
collab-check: | |
runs-on: ubuntu-latest | |
outputs: | |
approval-env: ${{ steps.collab-check.outputs.result }} | |
steps: | |
- name: Collaborator Check | |
uses: actions/github-script@v7 | |
id: collab-check | |
with: | |
github-token: ${{ github.token }} | |
result-encoding: string | |
script: | | |
try { | |
const res = await github.rest.repos.checkCollaborator({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
username: "${{ github.event.pull_request.user.login }}", | |
}); | |
console.log("Verifed ${{ github.event.pull_request.user.login }} is a repo collaborator. Auto Approving PR Checks.") | |
return res.status == "204" ? "auto-approve" : "manual-approval" | |
} catch (error) { | |
console.log("${{ github.event.pull_request.user.login }} is not a collaborator. Requiring Manual Approval to run PR Checks.") | |
return "manual-approval" | |
} | |
wait-for-approval: | |
runs-on: ubuntu-latest | |
needs: [collab-check] | |
environment: ${{ needs.collab-check.outputs.approval-env }} | |
steps: | |
- run: echo "Workflow Approved! Starting PR Checks." | |
test: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ['3.8', '3.7', '3.9', '3.10'] | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v2 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install dependencies | |
run: | | |
./devtool install_deps_dev | |
- name: Test | |
run: | | |
./devtool unit_tests | |
test_coverage-python-39: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.9' | |
- name: Install dependencies | |
run: | | |
./devtool install_deps_dev | |
- name: Run pre-commit checks and lint | |
run: | | |
./devtool lint | |
- name: Test with code coverage | |
run: | | |
./devtool test_with_coverage | |
- name: Generate documentation | |
run: | | |
./devtool docs | |
test_coverage-python-310: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.10' | |
- name: Install dependencies | |
run: | | |
./devtool install_deps_dev | |
- name: Run pre-commit checks and lint | |
run: | | |
./devtool lint | |
- name: Test with code coverage | |
run: | | |
./devtool test_with_coverage | |
- name: Generate documentation | |
run: | | |
./devtool docs |