Updating workflows (#46)

* updating workflows

* another test for deployment workflow

* making the workflows more polished
This commit is contained in:
Arnold Dechamps 2024-05-11 02:44:11 +02:00 committed by GitHub
parent 296c6e3720
commit 7e2dd22b10
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 43 additions and 17 deletions

View file

@ -1,23 +1,50 @@
name: Deploying name: Workflows on Master
on: on:
workflow_run: push:
workflows: ["Deploy", "Deploy static content to Pages"]
branches: branches:
- master - master
types:
- completed permissions:
contents: read
pages: write
id-token: write
jobs: jobs:
deploy_after_master_push: build_and_deploy:
runs-on: ubuntu-latest runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master' && (github.event_name == 'push' || github.event.workflow_run.conclusion == 'success')
steps: steps:
- name: Checkout Repository - name: Checkout Repository
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Deploy via SSH - name: Set up Python 3.11 for Flake8
if: github.event.workflow_run.name == 'Deploy' uses: actions/setup-python@v3
with:
python-version: "3.11"
- name: Install Flake8
run: pip install flake8
- name: Lint with Flake8
run: flake8 --ignore=E501,F401,E402,F811,E731,F403,E722 .
- name: Set up Python 3.11 for Django
uses: actions/setup-python@v3
with:
python-version: "3.11"
- name: Install Dependencies for Django
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
cp config.example.py config.py
- name: Run Tests for Django
run: |
python manage.py test
- name: Configure SSH for Deployment
if: success()
env: env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_HOST: ${{ secrets.SSH_HOST }} SSH_HOST: ${{ secrets.SSH_HOST }}
@ -34,15 +61,16 @@ jobs:
LogLevel ERROR LogLevel ERROR
StrictHostKeyChecking no StrictHostKeyChecking no
END END
- name: Deploy to Production
if: success() && github.ref == 'refs/heads/master'
needs: [build_and_deploy]
run: |
ssh target "cd tldtest && git pull origin master && docker-compose down && docker-compose up --build -d" ssh target "cd tldtest && git pull origin master && docker-compose down && docker-compose up --build -d"
- name: Deploy static content to GitHub Pages - name: Deploy static content to GitHub Pages
if: github.event.workflow_run.name == 'Deploy static content to Pages' if: success() && github.ref == 'refs/heads/master'
uses: actions/checkout@v4 needs: [build_and_deploy]
with:
ref: ${{ github.event.workflow_run.head_commit.sha }}
- name: Deploy static content to Pages
if: github.event.workflow_run.name == 'Deploy static content to Pages'
uses: actions/deploy-pages@v4 uses: actions/deploy-pages@v4
with: with:
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}

View file

@ -1,8 +1,6 @@
name: Django test and Flake 8 name: Django test and Flake 8
on: on:
push:
branches: [ "master" ]
pull_request: pull_request:
branches: [ "master" ] branches: [ "master" ]