Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

ci: fix inability to push to protected branches, workflow dispatch #65

Merged
merged 2 commits into from
Mar 24, 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
22 changes: 14 additions & 8 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,34 @@ on: [pull_request]
jobs:
lint:
runs-on: ubuntu-latest
permissions:
# Give the default GITHUB_TOKEN write permission to commit and push the changed files back to the repository.
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
uses: actions/[email protected]
with:
show-progress: false

- name: Lint
uses: psf/black@stable
with:
options: "-t py312"

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5.0.0
with:
python-version: 3.12 # ajusta esto según tus necesidades
python-version: 3.12

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install autoflake

- name: Remove unused variables
run: autoflake --recursive --in-place --exclude=settings.py --remove-all-unused-imports --remove-duplicate-keys --remove-unused-variables .
- name: Git config
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"

- name: Push formatted code
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "style: lint code"
commit_message: "style: lint code"
34 changes: 24 additions & 10 deletions .github/workflows/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ concurrency:
on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop

jobs:
generate:
runs-on: ubuntu-latest
Expand All @@ -24,6 +23,9 @@ jobs:
DB_PASSWORD: ocialpass123
DB_HOST: localhost
DB_PORT: 5432

permissions:
contents: write

steps:
- name: Checkout ⬇️
Expand All @@ -45,18 +47,30 @@ jobs:
run: python ./manage.py spectacular --file openapi.yaml --validate --fail-on-warn

- name: Check if the schema was modified
if: ${{ github.event_name == 'push' }}
id: diff
run: echo "count=$(git status -su | grep openapi.yaml | wc -l)" >> $GITHUB_OUTPUT

# "echo" in commit returns true so the build succeeds, even if no changed files
- name: Commit new changes to the repo
if: ${{ steps.diff.outputs.count > 0 && github.event_name != 'pull_request' }}
# In case other workflows pushed changes before this one
- name: Pull new changes
if: ${{ steps.diff.outputs.count > 0 && github.event_name == 'push' }}
run: |
git config user.name GitHub Actions
git config user.email [email protected]
git config pull.rebase true
git config rebase.autoStash true
git pull
git add .
git commit -m "ci: update OpenAPI schema" || echo
git push

- name: Push formatted code
if: ${{ steps.diff.outputs.count > 0 && github.event_name == 'push' }}
uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "ci: update openapi.yaml"

- name: Trigger generation workflow in axios-apiclient
if: ${{ steps.diff.outputs.count > 0 && github.event_name == 'push' }}
uses: convictional/[email protected]
with:
owner: ispp-2324-ocial
repo: axios-apiclient
github_token: ${{ secrets.GH_TOKEN }}
workflow_file_name: generation.yml
wait_workflow: false