Repository: GispoCoding/qgis_plugin_tools (language: python)

Issue:
Make pre-release only after tests succeed
Test and pre-release workflow should be combined so that pre-release is only made if the tests are a success.

Also, in my opinion dev pre-release should only be made when master/main branch is updated, perhaps a different tag for the latest pull request?


Discussion / hints:

Fix patch:
diff --git a/infrastructure/template/root/.github/workflows/prerelease.yml b/infrastructure/template/root/.github/workflows/prerelease.yml
deleted file mode 100644
index 80b498d..0000000
--- a/infrastructure/template/root/.github/workflows/prerelease.yml
+++ /dev/null
@@ -1,40 +0,0 @@
-name: Pre-release
-
-on:
-  pull_request:
-    branches:
-      - master
-      - main
-
-jobs:
-  pre-release:
-    name: "Pre Release"
-    runs-on: "ubuntu-latest"
-
-    steps:
-      - uses: "marvinpinto/action-automatic-releases@latest"
-        with:
-          repo_token: "${{ secrets.GITHUB_TOKEN }}"
-          automatic_release_tag: "dev"
-          prerelease: true
-          title: "Development Build made for PR #${{ github.event.number }}"
-
-      - uses: actions/checkout@v2
-        with:
-          submodules: true
-
-      - name: Set up Python 3.8
-        uses: actions/setup-python@v1
-        with:
-          python-version: 3.8
-
-      #    Needed if the plugin is using Transifex, to have the lrelease command
-      #    - name: Install Qt lrelease
-      #      run: sudo apt-get update && sudo apt-get install qt5-default qttools5-dev-tools
-
-      - name: Install qgis-plugin-ci
-        run: pip3 install qgis-plugin-ci
-
-      # When Transifex is wanted: --transifex-token ${{ secrets.TRANSIFEX_TOKEN }}
-      - name: Deploy plugin
-        run: qgis-plugin-ci release dev --github-token ${{ secrets.GITHUB_TOKEN }} --disable-submodule-update


Test patch:
diff --git a/infrastructure/template/root/.github/workflows/test-and-pre-release.yml b/infrastructure/template/root/.github/workflows/test-and-pre-release.yml
new file mode 100644
index 0000000..141f1a7
--- /dev/null
+++ b/infrastructure/template/root/.github/workflows/test-and-pre-release.yml
@@ -0,0 +1,115 @@
+# workflow name
+name: Tests
+
+# Controls when the action will run. Triggers the workflow on push or pull request
+# events but only for the wanted branches
+on:
+  pull_request:
+  push:
+    branches: [master, main]
+
+# A workflow run is made up of one or more jobs that can run sequentially or in parallel
+jobs:
+  linux_tests:
+    # The type of runner that the job will run on
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        # Remove unsupported versions and add more versions. Use LTR version in the cov_tests job
+        docker_tags: [release-3_10, release-3_16, latest]
+      fail-fast: false
+
+    # Steps represent a sequence of tasks that will be executed as part of the job
+    steps:
+      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
+      - uses: actions/checkout@v2
+        with:
+          submodules: true
+
+      - name: Pull qgis
+        run: docker pull qgis/qgis:${{ matrix.docker_tags }}
+
+      # Runs all tests
+      - name: Run tests
+        run: docker run --rm --net=host --volume `pwd`:/app -w=/app -e QGIS_PLUGIN_IN_CI=1 qgis/qgis:${{ matrix.docker_tags }} sh -c "pip3 install -q pytest pytest-cov && xvfb-run -s '+extension GLX -screen 0 1024x768x24' pytest -v --cov --cov-report=xml"
+
+      # Upload coverage report. Will not work if the repo is private
+      - name: Upload coverage to Codecov
+        if: ${{ matrix.docker_tags == 'latest' && !github.event.repository.private }}
+        uses: codecov/codecov-action@v1
+        with:
+          file: ./coverage.xml
+          flags: unittests
+          fail_ci_if_error: false # set to true when upload is working
+          verbose: false
+
+  windows_tests:
+    runs-on: windows-latest
+
+    steps:
+      - uses: actions/checkout@v2
+        with:
+          submodules: true
+
+      - name: Choco install qgis
+        uses: crazy-max/ghaction-chocolatey@v1
+        with:
+          args: install qgis-ltr -y
+
+      - name: Run tests
+        shell: pwsh
+        run: |
+          $env:PATH="C:\Program Files\QGIS 3.16\bin;$env:PATH"
+          $env:QGIS_PLUGIN_IN_CI=1
+          python-qgis-ltr.bat -m pip install -q pytest
+          python-qgis-ltr.bat -m pytest -v
+
+  pre-release:
+    name: "Pre Release"
+    runs-on: "ubuntu-latest"
+    needs: [linux_tests, windows_tests]
+
+    steps:
+      - uses: hmarr/debug-action@v2
+
+      - uses: "marvinpinto/action-automatic-releases@latest"
+        if: ${{ github.event.pull_request }}
+        with:
+          repo_token: "${{ secrets.GITHUB_TOKEN }}"
+          automatic_release_tag: "dev-pr"
+          prerelease: true
+          title: "Development Build made for PR #${{ github.event.number }}"
+
+      - uses: "marvinpinto/action-automatic-releases@latest"
+        if: ${{ github.event.after != github.event.before }}
+        with:
+          repo_token: "${{ secrets.GITHUB_TOKEN }}"
+          automatic_release_tag: "dev"
+          prerelease: true
+          title: "Development Build made for master branch"
+
+      - uses: actions/checkout@v2
+        with:
+          submodules: true
+
+      - name: Set up Python 3.8
+        uses: actions/setup-python@v1
+        with:
+          python-version: 3.8
+
+      #    Needed if the plugin is using Transifex, to have the lrelease command
+      #    - name: Install Qt lrelease
+      #      run: sudo apt-get update && sudo apt-get install qt5-default qttools5-dev-tools
+
+      - name: Install qgis-plugin-ci
+        run: pip3 install qgis-plugin-ci
+
+      # When Transifex is wanted: --transifex-token ${{ secrets.TRANSIFEX_TOKEN }}
+      - name: Deploy plugin
+        if: ${{ github.event.pull_request }}
+        run: qgis-plugin-ci release dev-pr --github-token ${{ secrets.GITHUB_TOKEN }} --disable-submodule-update
+
+        # When Transifex is wanted: --transifex-token ${{ secrets.TRANSIFEX_TOKEN }}
+      - name: Deploy plugin
+        if: ${{ github.event.after != github.event.before }}
+        run: qgis-plugin-ci release dev --github-token ${{ secrets.GITHUB_TOKEN }} --disable-submodule-update
diff --git a/infrastructure/template/root/.github/workflows/tests.yml b/infrastructure/template/root/.github/workflows/tests.yml
deleted file mode 100644
index ad2cdaa..0000000
--- a/infrastructure/template/root/.github/workflows/tests.yml
+++ /dev/null
@@ -1,79 +0,0 @@
-# workflow name
-name: Tests
-
-# Controls when the action will run. Triggers the workflow on push or pull request
-# events but only for the wanted branches
-on:
-  pull_request:
-  push:
-    branches: [master, main]
-
-# A workflow run is made up of one or more jobs that can run sequentially or in parallel
-jobs:
-  linux_tests:
-    # The type of runner that the job will run on
-    runs-on: ubuntu-latest
-    strategy:
-      matrix:
-        # Remove unsupported versions and add more versions. Use LTR version in the cov_tests job
-        docker_tags: [release-3_10, latest]
-      fail-fast: false
-
-    # Steps represent a sequence of tasks that will be executed as part of the job
-    steps:
-      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
-      - uses: actions/checkout@v2
-        with:
-          submodules: true
-
-      - name: Pull qgis
-        run: docker pull qgis/qgis:${{ matrix.docker_tags }}
-
-      # Runs all tests
-      - name: Run tests
-        run: docker run --rm --net=host --volume `pwd`:/app -w=/app -e QGIS_PLUGIN_IN_CI=1 qgis/qgis:${{ matrix.docker_tags }} sh -c "pip3 install -q pytest && xvfb-run -s '+extension GLX -screen 0 1024x768x24' pytest -v"
-
-  cov_tests:
-    runs-on: ubuntu-latest
-
-    steps:
-      - uses: actions/checkout@v2
-        with:
-          submodules: true
-
-      - name: Pull qgis LTR image
-        run: docker pull qgis/qgis:release-3_16
-
-      # Runs all tests
-      - name: Run tests (LTR)
-        run: docker run --rm --net=host --volume `pwd`:/app -w=/app -e QGIS_PLUGIN_IN_CI=1 qgis/qgis:release-3_16 sh -c "pip3 install -q pytest pytest-cov && xvfb-run -s '+extension GLX -screen 0 1024x768x24' pytest -v --cov --cov-report=xml"
-
-      # Upload coverage report
-      - name: Upload coverage to Codecov
-        uses: codecov/codecov-action@v1
-        with:
-          file: ./coverage.xml
-          flags: unittests
-          fail_ci_if_error: false # set to true when upload is working
-          verbose: false
-
-  windows_tests:
-    runs-on: windows-latest
-
-    steps:
-      - uses: actions/checkout@v2
-        with:
-          submodules: true
-
-      - name: Choco install qgis
-        uses: crazy-max/ghaction-chocolatey@v1
-        with:
-          args: install qgis-ltr -y
-
-      - name: Run tests
-        shell: pwsh
-        run: |
-          $env:PATH="C:\Program Files\QGIS 3.16\bin;$env:PATH"
-          $env:QGIS_PLUGIN_IN_CI=1
-          python-qgis-ltr.bat -m pip install -q pytest
-          python-qgis-ltr.bat -m pytest -v