From 7ee2481fdcf043d8d1af7f60d273f8bd913760ca Mon Sep 17 00:00:00 2001 From: Damian Birchler Date: Tue, 10 Oct 2023 08:06:44 +0200 Subject: [PATCH] Use variables to make `if` conditions more readable. --- .github/workflows/build-exe.yml | 19 +++++++++++++++---- .github/workflows/run-tests.yml | 17 ++++++++++++++++- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build-exe.yml b/.github/workflows/build-exe.yml index eecc7c9e..e10035c8 100644 --- a/.github/workflows/build-exe.yml +++ b/.github/workflows/build-exe.yml @@ -2,6 +2,8 @@ name: Build EXE on: push: + branches: + - master tags: - v* repository_dispatch: @@ -12,15 +14,22 @@ on: jobs: build-exe: runs-on: [self-hosted, etzel] + env: + NORMAL_PUSH_TO_MASTER: ${{github.event_name == 'repository_dispatch' && github.event.client_payload.type == 'build-executable-push'}} + TAG_PUSH_TO_MASTER: ${{github.event_name == 'push'}} + PUSH_TO_PULL_REQUEST: ${{github.event_name == 'repository_dispatch' && github.event.client_payload.type == 'build-executable-pull-request'}} steps: - uses: actions/checkout@v3 + - name: Report github.event_name and event_type run: | echo "Event name: ${{github.event_name}}" echo "Event type (via client payload): ${{github.event.client_payload.type}}" echo "Event type (via event_type): ${{github.event.event_type}}" + - name: Build executable run: py -3.9 dev-tools/devTools.py -x + - name: Compute file name id: fn run: | @@ -28,10 +37,12 @@ jobs: $pytrnsys_sha=$(release\pyinstaller-venv\Scripts\pip show pytrnsys | Select-String -Pattern "^Version:.*$").Matches.Value.Split(".")[-1].Substring(0,7) $ref_name="${{github.ref_name}}".replace("/","-") echo "file_name_base=pytrnsys-gui-${ref_name}-${pytrnsys_gui_sha}-${pytrnsys_sha}" >> $env:GITHUB_OUTPUT - - if: ${{github.event_name == 'push' || (github.event_name == 'repository_dispatch' && github.event.client_payload.type == 'build-executable-push')}} + + - if: ${{env.TAG_PUSH_TO_MASTER || env.NORMAL_PUSH_TO_MASTER}} name: Create zip file run: Compress-Archive -Path data, release\pyinstaller-venv\pytrnsys_data, release\dist -DestinationPath ${{steps.fn.outputs.file_name_base}}.zip - - if: ${{github.event_name == 'repository_dispatch' && github.event.client_payload.type == 'build-executable-push'}} + + - if: ${{env.NORMAL_PUSH_TO_MASTER}} name: Release artifacts (bleeding-edge) uses: "marvinpinto/action-automatic-releases@latest" with: @@ -42,7 +53,7 @@ jobs: # ATTENTION: `action-automatic-releases` *needs* forward slashes in the paths given to `files`. files: ${{steps.fn.outputs.file_name_base}}.zip - - if: ${{github.event_name == 'push'}} + - if: ${{env.TAG_PUSH_TO_MASTER}} name: Release artifacts (proper release) uses: "marvinpinto/action-automatic-releases@latest" with: @@ -52,7 +63,7 @@ jobs: # ATTENTION: `action-automatic-releases` *needs* forward slashes in the paths given to `files`. files: ${{steps.fn.outputs.file_name_base}}.zip - - if: ${{github.event_name == 'repository_dispatch' && github.event.client_payload.type == 'build-executable-pull-request'}} + - if: $${{env.PUSH_TO_PULL_REQUEST}} name: Upload artifacts uses: actions/upload-artifact@v3 with: diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index d041e855..c17aaba6 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -14,37 +14,50 @@ on: jobs: test: runs-on: [self-hosted, etzel] + env: + PYTRNSYS_DEPENDENCY_CHANGED: ${{github.event_name == 'repository_dispatch' && github.event.client_payload.type == 'run-tests-and-build-executable'}} steps: - uses: actions/checkout@v3 + - name: Remove old venv run: | if (Test-Path -LiteralPath venv) { Remove-Item -LiteralPath venv -Recurse } + - name: Create virtual environment run: py -3.9 -m venv venv + - name: Install dependencies run: | venv\Scripts\python -m pip install --upgrade pip venv\Scripts\python -m pip install wheel venv\Scripts\python -m pip install -r requirements/test.txt + - name: Generate UI code from Qt Creator Studio .ui files run: venv\Scripts\python dev-tools/generateGuiClassesFromQtCreatorStudioUiFiles.py + - name: Static type checking with mypy run: venv\Scripts\python dev-tools/devTools.py --type + - name: Lint with pylint run: venv\Scripts\python dev-tools/devTools.py --lint --keep-results + - name: Syntax checking with black run: venv\Scripts\python dev-tools/devTools.py --black --keep-results + - name: Generate class and package diagrams run: venv\Scripts\python dev-tools/devTools.py --diagram=dot --keep-results + - name: Test with pytest run: venv\Scripts\python dev-tools/devTools.py --unit --keep-results + - name: Post coverage report to Coveralls uses: coverallsapp/github-action@master with: github-token: ${{ secrets.GITHUB_TOKEN }} path-to-lcov: test-results/coverage.lcov + - name: Upload test results and coverage reports uses: actions/upload-artifact@v3 with: @@ -52,6 +65,7 @@ jobs: path: test-results # Use always() to always run this step to publish test results when there are test failures if: ${{ always() }} + - if: ${{github.event_name == 'pull_request'}} name: Trigger build of executable for pull request uses: peter-evans/repository-dispatch@v2 @@ -60,7 +74,8 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} event-type: build-executable-pull-request client-payload: '{"type": "build-executable-pull-request"}' - - if: ${{github.event_name == 'push'}} + + - if: ${{github.event_name == 'push' || env.PYTRNSYS_DEPENDENCY_CHANGED}} name: Trigger build of executable for push uses: peter-evans/repository-dispatch@v2 with: