Updated CI with pull push options and ci branch #6
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
| name: CI | ||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| - master | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| - master | ||
| env: # configure environment variables for git commits | ||
| actor: "41898282+github-actions[bot]" | ||
| jobs: | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout code for push | ||
| if: github.event_name == 'push' | ||
| uses: actions/checkout@v3 | ||
| with: | ||
| fetch-depth: 0 | ||
| ref: ${{ github.ref_name }} | ||
| - name: Checkout code for pull request | ||
| if: github.event_name == 'pull_request' | ||
| uses: actions/checkout@v3 | ||
| with: | ||
| fetch-depth: 0 | ||
| ref: ${{ github.head_ref }} | ||
| - name: Set up Python 3.11 | ||
| uses: actions/setup-python@v3 | ||
| with: | ||
| python-version: "3.11" | ||
| - name: Install dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| pip install pytest black flake8 # also install black & flake8 | ||
| if [ -f requirements.txt ]; then | ||
| pip install -r requirements.txt | ||
| fi | ||
| - name: Configure git # use the environment variable we set above | ||
| run: | | ||
| git config --local user.email "${actor}@users.noreply.github.com" | ||
| git config --local user.name "$actor" | ||
| - name: Test | ||
| run: | | ||
| pytest . | ||
| - name: Format & lint | ||
| run: | | ||
| black . # first run black, then run flake8 | ||
| flake8 --extend-ignore E203 --max-line-length 88 . | ||
| - name: Commit and push changes | ||
| run: | | ||
| git add . | ||
| git commit -m "🎨 Style code" || echo "No changes to commit" | ||
| git push | ||