Repository: cobbler/cobbler (language: python)

Issue:
[Backport] Don't execute GitHub release action in forks
### Original feature issue

- Issue: https://github.com/cobbler/cobbler/issues/3743
- PR: https://github.com/cobbler/cobbler/pull/3768

### Target release

- [x] release33
- [ ] release32
- [ ] release30

### Reason

Alignment with Uyuni/SUMA patches, to be more exact to aid that the `openSUSE/cobbler` repo is easier to maintain.



Discussion / hints:

Fix patch:
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
index 9a0f161d1d..3246ea0ac9 100644
--- a/.github/workflows/codeql-analysis.yml
+++ b/.github/workflows/codeql-analysis.yml
@@ -38,7 +38,7 @@ jobs:
 
     steps:
     - name: Checkout repository
-      uses: actions/checkout@v2
+      uses: actions/checkout@v4
 
     # Initializes the CodeQL tools for scanning.
     - name: Initialize CodeQL
diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml
index 99fcd1b1c5..f9eacdc948 100644
--- a/.github/workflows/lint.yml
+++ b/.github/workflows/lint.yml
@@ -10,7 +10,7 @@ jobs:
   lint_docs:
     runs-on: ubuntu-20.04
     steps:
-    - uses: actions/checkout@v2
+    - uses: actions/checkout@v4
     - name: Set up Python
       uses: actions/setup-python@v1
       with:
@@ -24,7 +24,7 @@ jobs:
   lint_shellscripts:
     runs-on: ubuntu-20.04
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v4
       - name: Run ShellCheck
         uses: ludeeus/action-shellcheck@master
         with:
diff --git a/.github/workflows/packaging.yml b/.github/workflows/packaging.yml
index b5ca0cfcd0..abc332c4b0 100644
--- a/.github/workflows/packaging.yml
+++ b/.github/workflows/packaging.yml
@@ -10,7 +10,7 @@ jobs:
   build-centos8-rpms:
     runs-on: ubuntu-20.04
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v4
       - name: Build a Rocky Linux 8 Package
         shell: 'script -q -e -c "bash {0}"'
         run: |
@@ -18,7 +18,7 @@ jobs:
   build-fedora34-rpms:
     runs-on: ubuntu-20.04
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v4
       - name: Build a Fedora 34 Package
         shell: 'script -q -e -c "bash {0}"'
         run: |
@@ -26,7 +26,7 @@ jobs:
   build-opensuse-leap-rpms:
     runs-on: ubuntu-20.04
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v4
       - name: Build a openSUSE Leap 15.3 Package
         shell: 'script -q -e -c "bash {0}"'
         run: |
@@ -34,7 +34,7 @@ jobs:
   build-opensuse-tumbleweed-rpms:
     runs-on: ubuntu-20.04
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v4
       - name: Build a openSUSE Tumbleweed Package
         shell: 'script -q -e -c "bash {0}"'
         run: |
@@ -42,7 +42,7 @@ jobs:
   build-debian10-debs:
     runs-on: ubuntu-20.04
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v4
       - name: Build a Debian 10 Package
         shell: 'script -q -e -c "bash {0}"'
         run: |
@@ -50,7 +50,7 @@ jobs:
   build-debian11-debs:
     runs-on: ubuntu-20.04
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v4
       - name: Build a Debian 11 Package
         shell: 'script -q -e -c "bash {0}"'
         run: |
@@ -58,7 +58,7 @@ jobs:
   build-debian12-debs:
     runs-on: ubuntu-20.04
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v4
       - name: Build a Debian 12 Package
         shell: 'script -q -e -c "bash {0}"'
         run: |
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 5e21e6760a..feb62537eb 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -2,6 +2,8 @@ name: Publish Python distributions to PyPI
 
 on:
   push:
+    branches:
+      - main
     tags:
       - 'v*'
 
@@ -27,10 +29,11 @@ env:
 
 jobs:
   build-n-publish:
+    if: github.repository == 'cobbler/cobbler'
     name: Build and publish Python distributions to PyPI and TestPyPI
     runs-on: ubuntu-latest
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v4
       - name: Set up Python 3.9
         uses: actions/setup-python@v2
         with:
@@ -64,14 +67,25 @@ jobs:
           libsasl2-dev
       - name: Install Deps for installing project
         run: pip install Sphinx coverage wheel
+      - name: Fetch date for version bump
+        run: echo "new_version=$(date +'%Y%m%d%H%M')" >> $GITHUB_ENV
+      - name: Replace version in setup.py
+        if: startsWith(github.ref, 'refs/tags/v') != true && github.ref == 'refs/heads/main'
+        run: sed -i '/VERSION = "[0-9].[0-9].[0-9]/s/.$/.'${{ env.new_version }}'"/g' setup.py
       - name: Install Deps with pip
         run: pip install .
       - name: Install pypa/build
         run: python -m pip install build --user
       - name: Build a binary wheel and a source tarball
         run: python setup.py sdist bdist_wheel
+      - name: Publish distribution to Test PyPI
+        if: github.ref == 'refs/heads/main'
+        uses: pypa/gh-action-pypi-publish@master
+        with:
+          password: ${{ secrets.TEST_PYPI_API_TOKEN }}
+          repository_url: https://test.pypi.org/legacy/
       - name: Publish distribution to PyPI
-        if: startsWith(github.ref, 'refs/tags')
+        if: startsWith(github.ref, 'refs/tags/v')
         uses: pypa/gh-action-pypi-publish@master
         with:
           password: ${{ secrets.PYPI_API_TOKEN }}
diff --git a/.github/workflows/release_master.yml b/.github/workflows/release_master.yml
deleted file mode 100644
index 0908deaee8..0000000000
--- a/.github/workflows/release_master.yml
+++ /dev/null
@@ -1,81 +0,0 @@
-name: Publish Python distributions to TestPyPI
-
-on:
-  push:
-    branches:
-      - main
-
-env:
-  DATAPATH: "/usr/share/cobbler"
-  DOCPATH: "/usr/share/man"
-  ETCPATH: "/etc/cobbler"
-  LIBPATH: "/var/lib/cobbler"
-  LOGPATH: "/var/log"
-  COMPLETION_PATH: "/usr/share/bash-completion/completions"
-  STATEPATH: "/tmp/cobbler_settings/devinstall"
-  HTTPD_SERVICE: "apache2.service"
-  WEBROOT: "/var/www"
-  WEBCONFIG: "/etc/apache2/sites-available"
-  WEBROOTCONFIG: "/etc/apache2"
-  TFTPROOT: "/srv/tftpboot"
-  DEFAULTPATH: "etc/sysconfig"
-  APACHE_USER: "www-data"
-  HTTP_USER: "www-data"
-  APACHE_GROUP: "www-data"
-
-# FIXME: We removed createrepo_c due to: https://answers.launchpad.net/createrepo/+question/690448
-
-jobs:
-  build-n-publish:
-    name: Build and publish Python distributions to TestPyPI
-    runs-on: ubuntu-latest
-    steps:
-      - uses: actions/checkout@v2
-      - name: Set up Python 3.9
-        uses: actions/setup-python@v2
-        with:
-          python-version: 3.9
-      - name: Update package cache
-        run: sudo apt-get -yq update
-      - name: Install all dependencies
-        run: >-
-          sudo apt-get -yq install
-          wget
-          pycodestyle
-          pyflakes3
-          liblocale-gettext-perl
-          lsb-release
-          xz-utils
-          bzip2
-          dpkg-dev
-          tftpd-hpa
-          rsync
-          xorriso
-          fence-agents
-          fakeroot
-          patch
-          pax
-          git
-          hardlink
-          apache2
-          apache2-dev
-          libapache2-mod-wsgi-py3
-          systemd
-          libsasl2-dev
-      - name: Install Deps for installing project
-        run: pip install Sphinx coverage wheel
-      - name: Fetch date for version bump
-        run: echo "new_version=$(date +'%Y%m%d%H%M')" >> $GITHUB_ENV
-      - name: Replace version in setup.py
-        run: sed -i '/VERSION = "[0-9].[0-9].[0-9]/s/.$/.'${{ env.new_version }}'"/g' setup.py
-      - name: Install Deps with pip
-        run: pip install .
-      - name: Install pypa/build
-        run: python -m pip install build --user
-      - name: Build a binary wheel and a source tarball
-        run: python setup.py sdist bdist_wheel
-      - name: Publish distribution to Test PyPI
-        uses: pypa/gh-action-pypi-publish@master
-        with:
-          password: ${{ secrets.TEST_PYPI_API_TOKEN }}
-          repository_url: https://test.pypi.org/legacy/
diff --git a/changelog.d/3769.added b/changelog.d/3769.added
new file mode 100644
index 0000000000..9b311199b9
--- /dev/null
+++ b/changelog.d/3769.added
@@ -0,0 +1,1 @@
+CI: Add repository filter condition for release workflow
\ No newline at end of file


Test patch:
diff --git a/.github/workflows/performance_testing.yml b/.github/workflows/performance_testing.yml
index 33a6558105..1cf961e3bb 100644
--- a/.github/workflows/performance_testing.yml
+++ b/.github/workflows/performance_testing.yml
@@ -10,7 +10,7 @@ jobs:
   run_performance_tests:
     runs-on: ubuntu-20.04
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v4
       - name: Pull Docker Test Container
         run: docker pull registry.opensuse.org/systemsmanagement/cobbler/github-ci/containers/cobbler-test-github:release33
       - name: Run previously built Docker Container
diff --git a/.github/workflows/system_testing.yml b/.github/workflows/system_testing.yml
index b851775abc..328b135d9f 100644
--- a/.github/workflows/system_testing.yml
+++ b/.github/workflows/system_testing.yml
@@ -11,7 +11,7 @@ jobs:
     runs-on: ubuntu-20.04
     steps:
       - name: Checkout repository
-        uses: actions/checkout@v2
+        uses: actions/checkout@v4
       - name: Pull Docker Test Container
         run: docker pull registry.opensuse.org/systemsmanagement/cobbler/github-ci/containers/cobbler-test-github:release33
       - name: Run previously built Docker Container
diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml
index f8db336f7c..27fb49805c 100644
--- a/.github/workflows/testing.yml
+++ b/.github/workflows/testing.yml
@@ -10,7 +10,7 @@ jobs:
   run_tests:
     runs-on: ubuntu-20.04
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v4
       - name: Pull Docker Test Container
         run: docker pull registry.opensuse.org/systemsmanagement/cobbler/github-ci/containers/cobbler-test-github:release33
       - name: Run previously built Docker Container