From 273ac0241570a29c98145fca602e9d9097bab96f Mon Sep 17 00:00:00 2001 From: Caique Marques Date: Wed, 16 Apr 2025 07:54:15 -0300 Subject: [PATCH 1/9] ci: add new action for building rpm packages --- .github/actions/.zip | Bin 0 -> 22 bytes .github/actions/buildrpm/Dockerfile | 29 +++++++++ .github/actions/buildrpm/action.yml | 10 ++++ .github/actions/buildrpm/entrypoint.sh | 8 +++ .github/actions/buildrpm/python-bytecode.spec | 55 ++++++++++++++++++ 5 files changed, 102 insertions(+) create mode 100644 .github/actions/.zip create mode 100644 .github/actions/buildrpm/Dockerfile create mode 100644 .github/actions/buildrpm/action.yml create mode 100644 .github/actions/buildrpm/entrypoint.sh create mode 100644 .github/actions/buildrpm/python-bytecode.spec diff --git a/.github/actions/.zip b/.github/actions/.zip new file mode 100644 index 0000000000000000000000000000000000000000..15cb0ecb3e219d1701294bfdf0fe3f5cb5d208e7 GIT binary patch literal 22 NcmWIWW@Tf*000g10H*)| literal 0 HcmV?d00001 diff --git a/.github/actions/buildrpm/Dockerfile b/.github/actions/buildrpm/Dockerfile new file mode 100644 index 00000000..c90c5851 --- /dev/null +++ b/.github/actions/buildrpm/Dockerfile @@ -0,0 +1,29 @@ +FROM opensuse/tumbleweed:latest + +# Update +RUN zypper patch -y + +# Install necessary packages +RUN zypper in -y \ + rpm-build rpmdevtools dnf-plugins-core python3 git gcc fdupes \ + python311-pip python311-setuptools python311-setuptools_scm python311-wheel python311-pytest \ + python312-pip python312-setuptools python312-setuptools_scm python312-wheel python312-pytest \ + python313-pip python313-setuptools python313-setuptools_scm python313-wheel python313-pytest + +# Create an user named rpmbuild +RUN useradd rpmuser -u 5002 -g users -p rpmbuild + +COPY python-bytecode.spec /home/rpmuser/python-bytecode.spec +COPY python-bytecode*.tar.gz /home/rpmuser/python-bytecode.tar.gz + +# Set up the entrypoint script +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +USER rpmuser + +WORKDIR /home/rpmbuild + +# Setup build directory +RUN rpmdev-setuptree +ENTRYPOINT ["/entrypoint.sh"] diff --git a/.github/actions/buildrpm/action.yml b/.github/actions/buildrpm/action.yml new file mode 100644 index 00000000..d3d5b2d1 --- /dev/null +++ b/.github/actions/buildrpm/action.yml @@ -0,0 +1,10 @@ +name: "Build RPM" +description: "Build RPM package" + +outputs: + rpm-package: + description: "Bytecode is a Python module to generate and modify bytecode" + +runs: + using: "docker" + image: "Dockerfile" diff --git a/.github/actions/buildrpm/entrypoint.sh b/.github/actions/buildrpm/entrypoint.sh new file mode 100644 index 00000000..e30533a7 --- /dev/null +++ b/.github/actions/buildrpm/entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +cd ~/ + +mv python-bytecode.spec rpmbuild/SPECS +mv python-bytecode.tar.gz rpmbuild/SOURCES + +rpmbuild -bb rpmbuild/SPECS/python-bytecode.spec diff --git a/.github/actions/buildrpm/python-bytecode.spec b/.github/actions/buildrpm/python-bytecode.spec new file mode 100644 index 00000000..3bda449d --- /dev/null +++ b/.github/actions/buildrpm/python-bytecode.spec @@ -0,0 +1,55 @@ +# +# spec file for package python-bytecode +# +# Copyright (c) 2025 SUSE LLC +# +# All modifications and additions to the file contributed by third parties +# remain the property of their copyright owners, unless otherwise agreed +# upon. The license for this file, and modifications and additions to the +# file, is the same license as for the pristine package itself (unless the +# license for the pristine package is not an Open Source License, in which +# case the license is the MIT License). An "Open Source License" is a +# license that conforms to the Open Source Definition (Version 1.9) +# published by the Open Source Initiative. + +# Please submit bugfixes or comments via https://bugs.opensuse.org/ +# + + +Name: python-bytecode +Version: 0.16.1 +Release: 1%{?dist} +Summary: Python module to generate and modify bytecode +License: MIT +URL: https://github.com/mrcaique/bytecode +Source: /github/home/rpmbuild/SOURCES/%{name}.tar.gz +BuildRequires: python-rpm-macros +BuildRequires: %{python_module pip} +BuildRequires: %{python_module setuptools >= 61.2} +BuildRequires: %{python_module setuptools_scm >= 3.4.3} +BuildRequires: %{python_module wheel} +BuildRequires: fdupes +BuildArch: noarch +%python_subpackages + +%description +Python module to generate and modify bytecode + +%prep +%autosetup -p1 -n bytecode + +%build +%pyproject_wheel + +%install +%pyproject_install +%python_expand %fdupes %{buildroot}%{$python_sitelib} + +%files %{python_files} +%doc README.rst +%license COPYING +%{python_sitelib}/bytecode +%{python_sitelib}/bytecode-*.dist-info + +%changelog + From 48f1af1abdd23144de6f14b788a0afd251887994 Mon Sep 17 00:00:00 2001 From: Caique Marques Date: Wed, 16 Apr 2025 07:55:10 -0300 Subject: [PATCH 2/9] ci: new workflow for building a rpm package and uploading it as an artifact --- .github/workflows/rpmbuild.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/rpmbuild.yml diff --git a/.github/workflows/rpmbuild.yml b/.github/workflows/rpmbuild.yml new file mode 100644 index 00000000..ac34ec8b --- /dev/null +++ b/.github/workflows/rpmbuild.yml @@ -0,0 +1,27 @@ +name: RPM build + +on: + push: + branches: [ main ] + +jobs: + build_rpm: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Create source archive + run: > + cd .. + && tar -czvf python-bytecode.tar.gz bytecode + && mv python-bytecode.tar.gz bytecode/.github/actions/buildrpm + + - name: Build RPM package + id: rpm + uses: ./.github/actions/buildrpm + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: Binary RPM + path: ${{ steps.rpm.outputs.rpm_dir_path }} From 39819ca20d2b99ee47f4d12aa15b4f7b5569b6e5 Mon Sep 17 00:00:00 2001 From: Caique Marques Date: Wed, 16 Apr 2025 07:57:58 -0300 Subject: [PATCH 3/9] fix: remove unnecessary file --- .github/actions/.zip | Bin 22 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .github/actions/.zip diff --git a/.github/actions/.zip b/.github/actions/.zip deleted file mode 100644 index 15cb0ecb3e219d1701294bfdf0fe3f5cb5d208e7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 22 NcmWIWW@Tf*000g10H*)| From 40ec2309a198f6991646b577b759617c18c83fad Mon Sep 17 00:00:00 2001 From: Caique Marques Date: Thu, 17 Apr 2025 11:51:11 -0300 Subject: [PATCH 4/9] ci: add rpm build to github workspace --- .github/actions/buildrpm/Dockerfile | 3 ++- .github/actions/buildrpm/entrypoint.sh | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/actions/buildrpm/Dockerfile b/.github/actions/buildrpm/Dockerfile index c90c5851..556a3bf9 100644 --- a/.github/actions/buildrpm/Dockerfile +++ b/.github/actions/buildrpm/Dockerfile @@ -10,9 +10,10 @@ RUN zypper in -y \ python312-pip python312-setuptools python312-setuptools_scm python312-wheel python312-pytest \ python313-pip python313-setuptools python313-setuptools_scm python313-wheel python313-pytest -# Create an user named rpmbuild +# Create an user named rpmuser and grant sudo access RUN useradd rpmuser -u 5002 -g users -p rpmbuild +# Copy necessary files to build a rpm package COPY python-bytecode.spec /home/rpmuser/python-bytecode.spec COPY python-bytecode*.tar.gz /home/rpmuser/python-bytecode.tar.gz diff --git a/.github/actions/buildrpm/entrypoint.sh b/.github/actions/buildrpm/entrypoint.sh index e30533a7..f3349b0d 100644 --- a/.github/actions/buildrpm/entrypoint.sh +++ b/.github/actions/buildrpm/entrypoint.sh @@ -6,3 +6,4 @@ mv python-bytecode.spec rpmbuild/SPECS mv python-bytecode.tar.gz rpmbuild/SOURCES rpmbuild -bb rpmbuild/SPECS/python-bytecode.spec +mv rpmbuild/RPMS/noarch/*.rpm /github/workspace From 3c29c3caf9e931be7c51886f0264e8f30241c904 Mon Sep 17 00:00:00 2001 From: Caique Marques Date: Thu, 17 Apr 2025 11:51:49 -0300 Subject: [PATCH 5/9] ci: accessing files created by the container action --- .github/workflows/rpmbuild.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/rpmbuild.yml b/.github/workflows/rpmbuild.yml index ac34ec8b..74d3b589 100644 --- a/.github/workflows/rpmbuild.yml +++ b/.github/workflows/rpmbuild.yml @@ -3,6 +3,8 @@ name: RPM build on: push: branches: [ main ] + pull_request: + branches: [ main ] jobs: build_rpm: @@ -13,15 +15,15 @@ jobs: - name: Create source archive run: > cd .. - && tar -czvf python-bytecode.tar.gz bytecode + && tar -czf python-bytecode.tar.gz bytecode && mv python-bytecode.tar.gz bytecode/.github/actions/buildrpm - name: Build RPM package id: rpm uses: ./.github/actions/buildrpm - - name: Upload artifact + - name: Upload RPM as artifact uses: actions/upload-artifact@v4 with: - name: Binary RPM - path: ${{ steps.rpm.outputs.rpm_dir_path }} + name: binary-rpm + path: ${{ github.workspace }} From cb0d98706eb23cb0f114e5ae10c7563b7ad20ffe Mon Sep 17 00:00:00 2001 From: Caique Marques Date: Thu, 17 Apr 2025 15:17:41 -0300 Subject: [PATCH 6/9] ci: fix paths --- .github/actions/buildrpm/Dockerfile | 15 +++++---------- .github/actions/buildrpm/entrypoint.sh | 10 +++------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/.github/actions/buildrpm/Dockerfile b/.github/actions/buildrpm/Dockerfile index 556a3bf9..0fa4e5ef 100644 --- a/.github/actions/buildrpm/Dockerfile +++ b/.github/actions/buildrpm/Dockerfile @@ -10,21 +10,16 @@ RUN zypper in -y \ python312-pip python312-setuptools python312-setuptools_scm python312-wheel python312-pytest \ python313-pip python313-setuptools python313-setuptools_scm python313-wheel python313-pytest -# Create an user named rpmuser and grant sudo access -RUN useradd rpmuser -u 5002 -g users -p rpmbuild +RUN rpmdev-setuptree + +WORKDIR /root/rpmbuild # Copy necessary files to build a rpm package -COPY python-bytecode.spec /home/rpmuser/python-bytecode.spec -COPY python-bytecode*.tar.gz /home/rpmuser/python-bytecode.tar.gz +COPY python-bytecode.spec SPECS/ +COPY python-bytecode.tar.gz SOURCES/ # Set up the entrypoint script COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh -USER rpmuser - -WORKDIR /home/rpmbuild - -# Setup build directory -RUN rpmdev-setuptree ENTRYPOINT ["/entrypoint.sh"] diff --git a/.github/actions/buildrpm/entrypoint.sh b/.github/actions/buildrpm/entrypoint.sh index f3349b0d..2dbf1648 100644 --- a/.github/actions/buildrpm/entrypoint.sh +++ b/.github/actions/buildrpm/entrypoint.sh @@ -1,9 +1,5 @@ #!/bin/bash +cd ~/rpmbuild/ -cd ~/ - -mv python-bytecode.spec rpmbuild/SPECS -mv python-bytecode.tar.gz rpmbuild/SOURCES - -rpmbuild -bb rpmbuild/SPECS/python-bytecode.spec -mv rpmbuild/RPMS/noarch/*.rpm /github/workspace +rpmbuild -bb SPECS/python-bytecode.spec +mv RPMS/noarch/*.rpm $GITHUB_WORKSPACE From fc28d3bb77d8c95e8b05a9fef16fdcb7de7e7e40 Mon Sep 17 00:00:00 2001 From: Caique Marques Date: Fri, 18 Apr 2025 01:20:06 -0300 Subject: [PATCH 7/9] ci: fix paths --- .github/actions/buildrpm/Dockerfile | 10 ++++------ .github/actions/buildrpm/entrypoint.sh | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/.github/actions/buildrpm/Dockerfile b/.github/actions/buildrpm/Dockerfile index 0fa4e5ef..04790e67 100644 --- a/.github/actions/buildrpm/Dockerfile +++ b/.github/actions/buildrpm/Dockerfile @@ -6,13 +6,11 @@ RUN zypper patch -y # Install necessary packages RUN zypper in -y \ rpm-build rpmdevtools dnf-plugins-core python3 git gcc fdupes \ - python311-pip python311-setuptools python311-setuptools_scm python311-wheel python311-pytest \ - python312-pip python312-setuptools python312-setuptools_scm python312-wheel python312-pytest \ - python313-pip python313-setuptools python313-setuptools_scm python313-wheel python313-pytest + python311-pip python311-setuptools python311-setuptools_scm python311-wheel \ + python312-pip python312-setuptools python312-setuptools_scm python312-wheel \ + python313-pip python313-setuptools python313-setuptools_scm python313-wheel -RUN rpmdev-setuptree - -WORKDIR /root/rpmbuild +WORKDIR /usr/src/packages # Copy necessary files to build a rpm package COPY python-bytecode.spec SPECS/ diff --git a/.github/actions/buildrpm/entrypoint.sh b/.github/actions/buildrpm/entrypoint.sh index 2dbf1648..07a8015b 100644 --- a/.github/actions/buildrpm/entrypoint.sh +++ b/.github/actions/buildrpm/entrypoint.sh @@ -1,5 +1,5 @@ #!/bin/bash -cd ~/rpmbuild/ +cd /usr/src/packages rpmbuild -bb SPECS/python-bytecode.spec mv RPMS/noarch/*.rpm $GITHUB_WORKSPACE From 122c451c4cae223fcd44543628e1552cf7034ded Mon Sep 17 00:00:00 2001 From: Caique Marques Date: Fri, 18 Apr 2025 02:04:39 -0300 Subject: [PATCH 8/9] ci: specify upload file path --- .github/workflows/rpmbuild.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rpmbuild.yml b/.github/workflows/rpmbuild.yml index 74d3b589..825e2802 100644 --- a/.github/workflows/rpmbuild.yml +++ b/.github/workflows/rpmbuild.yml @@ -25,5 +25,5 @@ jobs: - name: Upload RPM as artifact uses: actions/upload-artifact@v4 with: - name: binary-rpm - path: ${{ github.workspace }} + name: python-bytecode-binary-rpm + path: ${{ github.workspace }}/*.rpm From 4ee8cb2ed05ea8382c324963487800f403399ba7 Mon Sep 17 00:00:00 2001 From: Caique Marques Date: Fri, 18 Apr 2025 19:05:32 -0300 Subject: [PATCH 9/9] ci: build rpm package whenever a new release tag is created on main branch --- .github/actions/buildrpm/entrypoint.sh | 3 +++ .github/actions/buildrpm/python-bytecode.spec | 2 +- .github/workflows/rpmbuild.yml | 11 +++++++---- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.github/actions/buildrpm/entrypoint.sh b/.github/actions/buildrpm/entrypoint.sh index 07a8015b..3bddc475 100644 --- a/.github/actions/buildrpm/entrypoint.sh +++ b/.github/actions/buildrpm/entrypoint.sh @@ -1,5 +1,8 @@ #!/bin/bash cd /usr/src/packages +# Update release verion on spec file +sed -i -e "s/##RPMVERSION##/$RELEASE_VERSION/" SPECS/python-bytecode.spec + rpmbuild -bb SPECS/python-bytecode.spec mv RPMS/noarch/*.rpm $GITHUB_WORKSPACE diff --git a/.github/actions/buildrpm/python-bytecode.spec b/.github/actions/buildrpm/python-bytecode.spec index 3bda449d..2db69552 100644 --- a/.github/actions/buildrpm/python-bytecode.spec +++ b/.github/actions/buildrpm/python-bytecode.spec @@ -17,7 +17,7 @@ Name: python-bytecode -Version: 0.16.1 +Version: ##RPMVERSION## Release: 1%{?dist} Summary: Python module to generate and modify bytecode License: MIT diff --git a/.github/workflows/rpmbuild.yml b/.github/workflows/rpmbuild.yml index 825e2802..906d034a 100644 --- a/.github/workflows/rpmbuild.yml +++ b/.github/workflows/rpmbuild.yml @@ -2,16 +2,19 @@ name: RPM build on: push: - branches: [ main ] - pull_request: - branches: [ main ] + tags: + - 'v*.*.*' jobs: build_rpm: + if: ${{ github.event.base_ref == 'refs/heads/main' }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Set release version env + run: echo "RELEASE_VERSION=${GITHUB_REF:11}" >> $GITHUB_REF + - name: Create source archive run: > cd .. @@ -25,5 +28,5 @@ jobs: - name: Upload RPM as artifact uses: actions/upload-artifact@v4 with: - name: python-bytecode-binary-rpm + name: python-bytecode-binary-rpm-${{ env.RELEASE_VERSION }} path: ${{ github.workspace }}/*.rpm