From 36b8fec1ef137250c1527b4465b96b701cf1b898 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Fri, 28 Mar 2025 22:02:28 -0400 Subject: [PATCH 01/20] trying something --- .github/workflows/package-build.yaml | 79 ++++++++++++++++------------ 1 file changed, 46 insertions(+), 33 deletions(-) diff --git a/.github/workflows/package-build.yaml b/.github/workflows/package-build.yaml index 97d0fb91..cca754c9 100644 --- a/.github/workflows/package-build.yaml +++ b/.github/workflows/package-build.yaml @@ -2,22 +2,10 @@ name: Build and Release on: push: - tags: - - "v*" + branches: [build-sign-test] jobs: - check-branch: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - name: Verify tag is on main - run: | - if [ "$(git branch --contains $GITHUB_REF)" != "* main" ]; then - echo "Tag $GITHUB_REF is not on main branch" - exit 1 - fi build: - needs: check-branch runs-on: ${{ matrix.os }} strategy: matrix: @@ -32,7 +20,6 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up Python uses: actions/setup-python@v4 with: @@ -82,6 +69,40 @@ jobs: pyinstaller --onefile --name ecooptimizer-server-dev $(which eco-ext-dev) mv dist/ecooptimizer-server-dev dist/ecooptimizer-server-dev-${{ matrix.artifact_name }} + - name: Install signing tools + if: matrix.os == 'windows-latest' + run: | + choco install osslsigncode -y + + - name: Sign Windows binaries + if: matrix.os == 'windows-latest' + run: | + openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -subj "/CN=EcoOptimizer" + osslsigncode sign -certs cert.pem -key key.pem -n "EcoOptimizer" -t http://timestamp.digicert.com -in dist/ecooptimizer-server-${{ matrix.artifact_name }} -out dist/ecooptimizer-server-${{ matrix.artifact_name }}.signed + mv dist/ecooptimizer-server-${{ matrix.artifact_name }}.signed dist/ecooptimizer-server-${{ matrix.artifact_name }} + osslsigncode sign -certs cert.pem -key key.pem -n "EcoOptimizer" -t http://timestamp.digicert.com -in dist/ecooptimizer-server-dev-${{ matrix.artifact_name }} -out dist/ecooptimizer-server-dev-${{ matrix.artifact_name }}.signed + mv dist/ecooptimizer-server-dev-${{ matrix.artifact_name }}.signed dist/ecooptimizer-server-dev-${{ matrix.artifact_name }} + + - name: Sign macOS binaries + if: matrix.os == 'macos-latest' + run: | + codesign --force --deep --sign - dist/ecooptimizer-server-${{ matrix.artifact_name }} + codesign --force --deep --sign - dist/ecooptimizer-server-dev-${{ matrix.artifact_name }} + + - name: Set up GPG (Linux) + if: matrix.os == 'ubuntu-latest' + run: | + sudo apt-get install -y gpg + echo "${{ secrets.GPG_PRIVATE_KEY }}" | gpg --batch --import + gpg --list-secret-keys + + - name: Sign Linux binaries + if: matrix.os == 'ubuntu-latest' + run: | + cd dist + gpg --detach-sign --armor -u "${{ secrets.GPG_KEY_ID }}" ecooptimizer-server-${{ matrix.artifact_name }} + gpg --detach-sign --armor -u "${{ secrets.GPG_KEY_ID }}" ecooptimizer-server-dev-${{ matrix.artifact_name }} + - name: Upload artifacts uses: actions/upload-artifact@v4 with: @@ -89,6 +110,7 @@ jobs: path: | dist/ecooptimizer-server-* dist/ecooptimizer-server-dev-* + dist/*.asc # For Linux GPG signatures if-no-files-found: error create-release: @@ -100,7 +122,7 @@ jobs: with: path: artifacts pattern: artifacts-* - merge-multiple: false # Keep separate folders per OS + merge-multiple: false - name: Create release uses: softprops/action-gh-release@v1 @@ -109,24 +131,15 @@ jobs: name: ${{ github.ref_name }} body: | ${{ github.event.head_commit.message }} - - ## EcoOptimizer Server Executables - This release contains the standalone server executables for launching the EcoOptimizer analysis engine. - These are designed to work with the corresponding **EcoOptimizer VS Code Extension**. - - ### Included Artifacts - - **Production Server**: `ecooptimizer-server-` - (Stable version for production use) - - **Development Server**: `ecooptimizer-server-dev-` - (Development version with debug features) - - ### Platform Support - - Linux (`linux-x64`) - - Windows (`windows-x64.exe`) - - macOS (`macos-x64`) + + **Signed Artifacts:** + - Windows: Authenticode-signed + - macOS: Ad-hoc signed + - Linux: GPG-signed (.asc files) files: | - artifacts/artifacts-ubuntu-latest/dist/* - artifacts/artifacts-windows-latest/dist/* - artifacts/artifacts-macos-latest/dist/* + artifacts/artifacts-ubuntu-latest/* + artifacts/artifacts-windows-latest/* + artifacts/artifacts-macos-latest/* + draft: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From 1ec1732be402890aa52c9c4e05b2bdfccfbc189a Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Fri, 28 Mar 2025 22:10:50 -0400 Subject: [PATCH 02/20] fixing linux key entry --- .github/workflows/package-build.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/package-build.yaml b/.github/workflows/package-build.yaml index cca754c9..9a4c49d7 100644 --- a/.github/workflows/package-build.yaml +++ b/.github/workflows/package-build.yaml @@ -100,8 +100,8 @@ jobs: if: matrix.os == 'ubuntu-latest' run: | cd dist - gpg --detach-sign --armor -u "${{ secrets.GPG_KEY_ID }}" ecooptimizer-server-${{ matrix.artifact_name }} - gpg --detach-sign --armor -u "${{ secrets.GPG_KEY_ID }}" ecooptimizer-server-dev-${{ matrix.artifact_name }} + echo "${{ secrets.GPG_PASSPHRASE }}" | gpg --batch --yes --pinentry-mode loopback --detach-sign --armor -u "${{ secrets.GPG_KEY_ID }}" ecooptimizer-server-${{ matrix.artifact_name }} + echo "${{ secrets.GPG_PASSPHRASE }}" | gpg --batch --yes --pinentry-mode loopback --detach-sign --armor -u "${{ secrets.GPG_KEY_ID }}" ecooptimizer-server-dev-${{ matrix.artifact_name }} - name: Upload artifacts uses: actions/upload-artifact@v4 From 14829bf5066076edda958dc9f4f3b5a09c149dd6 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Fri, 28 Mar 2025 22:25:04 -0400 Subject: [PATCH 03/20] removed linux gpg key passphrase requirement --- .github/workflows/package-build.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/package-build.yaml b/.github/workflows/package-build.yaml index 9a4c49d7..871fd89b 100644 --- a/.github/workflows/package-build.yaml +++ b/.github/workflows/package-build.yaml @@ -100,8 +100,8 @@ jobs: if: matrix.os == 'ubuntu-latest' run: | cd dist - echo "${{ secrets.GPG_PASSPHRASE }}" | gpg --batch --yes --pinentry-mode loopback --detach-sign --armor -u "${{ secrets.GPG_KEY_ID }}" ecooptimizer-server-${{ matrix.artifact_name }} - echo "${{ secrets.GPG_PASSPHRASE }}" | gpg --batch --yes --pinentry-mode loopback --detach-sign --armor -u "${{ secrets.GPG_KEY_ID }}" ecooptimizer-server-dev-${{ matrix.artifact_name }} + gpg --batch --yes --detach-sign --armor -u "${{ secrets.GPG_KEY_ID }}" ecooptimizer-server-${{ matrix.artifact_name }} + gpg --batch --yes --detach-sign --armor -u "${{ secrets.GPG_KEY_ID }}" ecooptimizer-server-dev-${{ matrix.artifact_name }} - name: Upload artifacts uses: actions/upload-artifact@v4 From 30af7807fa68b8d80dcc8b3e00da0d88048f338c Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Fri, 28 Mar 2025 22:41:18 -0400 Subject: [PATCH 04/20] trying something else again --- .github/workflows/package-build.yaml | 34 +++++++++++++++++++--------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/.github/workflows/package-build.yaml b/.github/workflows/package-build.yaml index 871fd89b..b065fda4 100644 --- a/.github/workflows/package-build.yaml +++ b/.github/workflows/package-build.yaml @@ -12,9 +12,9 @@ jobs: os: [ubuntu-latest, windows-latest, macos-latest] include: - os: ubuntu-latest - artifact_name: linux-x64 + artifact_name: linux - os: windows-latest - artifact_name: windows-x64.exe + artifact_name: win.exe - os: macos-latest artifact_name: macos-x64 @@ -74,14 +74,26 @@ jobs: run: | choco install osslsigncode -y - - name: Sign Windows binaries - if: matrix.os == 'windows-latest' - run: | - openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -subj "/CN=EcoOptimizer" - osslsigncode sign -certs cert.pem -key key.pem -n "EcoOptimizer" -t http://timestamp.digicert.com -in dist/ecooptimizer-server-${{ matrix.artifact_name }} -out dist/ecooptimizer-server-${{ matrix.artifact_name }}.signed - mv dist/ecooptimizer-server-${{ matrix.artifact_name }}.signed dist/ecooptimizer-server-${{ matrix.artifact_name }} - osslsigncode sign -certs cert.pem -key key.pem -n "EcoOptimizer" -t http://timestamp.digicert.com -in dist/ecooptimizer-server-dev-${{ matrix.artifact_name }} -out dist/ecooptimizer-server-dev-${{ matrix.artifact_name }}.signed - mv dist/ecooptimizer-server-dev-${{ matrix.artifact_name }}.signed dist/ecooptimizer-server-dev-${{ matrix.artifact_name }} + - name: Sign Windows binaries + if: matrix.os == 'windows-latest' + shell: pwsh + run: | + # Generate cert + openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -subj "/CN=EcoOptimizer" + + # Sign in-place using temporary file + $TempFile = "dist\temp-signed.exe" + osslsigncode sign -certs cert.pem -key key.pem -n "EcoOptimizer" ` + -t http://timestamp.digicert.com ` + -in "dist\ecooptimizer-server-${{ matrix.artifact_name }}" ` + -out $TempFile + Move-Item -Path $TempFile -Destination "dist\ecooptimizer-server-${{ matrix.artifact_name }}" -Force + + osslsigncode sign -certs cert.pem -key key.pem -n "EcoOptimizer" ` + -t http://timestamp.digicert.com ` + -in "dist\ecooptimizer-server-dev-${{ matrix.artifact_name }}" ` + -out $TempFile + Move-Item -Path $TempFile -Destination "dist\ecooptimizer-server-dev-${{ matrix.artifact_name }}" -Force - name: Sign macOS binaries if: matrix.os == 'macos-latest' @@ -110,7 +122,7 @@ jobs: path: | dist/ecooptimizer-server-* dist/ecooptimizer-server-dev-* - dist/*.asc # For Linux GPG signatures + dist/*.asc if-no-files-found: error create-release: From a87fe3c88c86ef826cf8f09794b52945a0bd9425 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Fri, 28 Mar 2025 22:46:43 -0400 Subject: [PATCH 05/20] fixed silly typo --- .github/workflows/package-build.yaml | 40 ++++++++++++++-------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/.github/workflows/package-build.yaml b/.github/workflows/package-build.yaml index b065fda4..47524a87 100644 --- a/.github/workflows/package-build.yaml +++ b/.github/workflows/package-build.yaml @@ -74,26 +74,26 @@ jobs: run: | choco install osslsigncode -y - - name: Sign Windows binaries - if: matrix.os == 'windows-latest' - shell: pwsh - run: | - # Generate cert - openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -subj "/CN=EcoOptimizer" - - # Sign in-place using temporary file - $TempFile = "dist\temp-signed.exe" - osslsigncode sign -certs cert.pem -key key.pem -n "EcoOptimizer" ` - -t http://timestamp.digicert.com ` - -in "dist\ecooptimizer-server-${{ matrix.artifact_name }}" ` - -out $TempFile - Move-Item -Path $TempFile -Destination "dist\ecooptimizer-server-${{ matrix.artifact_name }}" -Force - - osslsigncode sign -certs cert.pem -key key.pem -n "EcoOptimizer" ` - -t http://timestamp.digicert.com ` - -in "dist\ecooptimizer-server-dev-${{ matrix.artifact_name }}" ` - -out $TempFile - Move-Item -Path $TempFile -Destination "dist\ecooptimizer-server-dev-${{ matrix.artifact_name }}" -Force + - name: Sign Windows binaries + if: matrix.os == 'windows-latest' + shell: pwsh + run: | + # Generate cert + openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -subj "/CN=EcoOptimizer" + + # Sign in-place using temporary file + $TempFile = "dist\temp-signed.exe" + osslsigncode sign -certs cert.pem -key key.pem -n "EcoOptimizer" ` + -t http://timestamp.digicert.com ` + -in "dist\ecooptimizer-server-${{ matrix.artifact_name }}" ` + -out $TempFile + Move-Item -Path $TempFile -Destination "dist\ecooptimizer-server-${{ matrix.artifact_name }}" -Force + + osslsigncode sign -certs cert.pem -key key.pem -n "EcoOptimizer" ` + -t http://timestamp.digicert.com ` + -in "dist\ecooptimizer-server-dev-${{ matrix.artifact_name }}" ` + -out $TempFile + Move-Item -Path $TempFile -Destination "dist\ecooptimizer-server-dev-${{ matrix.artifact_name }}" -Force - name: Sign macOS binaries if: matrix.os == 'macos-latest' From ce806980890f96ac6deb89fe2370230408b561ae Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Fri, 28 Mar 2025 22:55:57 -0400 Subject: [PATCH 06/20] Change build workflow to sign the binaries (#503) --- .github/workflows/package-build.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/package-build.yaml b/.github/workflows/package-build.yaml index 47524a87..e534613e 100644 --- a/.github/workflows/package-build.yaml +++ b/.github/workflows/package-build.yaml @@ -2,7 +2,8 @@ name: Build and Release on: push: - branches: [build-sign-test] + tags: + - "v*" jobs: build: @@ -16,7 +17,7 @@ jobs: - os: windows-latest artifact_name: win.exe - os: macos-latest - artifact_name: macos-x64 + artifact_name: macos steps: - uses: actions/checkout@v4 From b2fdca55105462be299fbdacd5eb9fb1b7811186 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Fri, 28 Mar 2025 23:41:13 -0400 Subject: [PATCH 07/20] Removed draft release specifier --- .github/workflows/package-build.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/package-build.yaml b/.github/workflows/package-build.yaml index e534613e..d18a909b 100644 --- a/.github/workflows/package-build.yaml +++ b/.github/workflows/package-build.yaml @@ -153,6 +153,5 @@ jobs: artifacts/artifacts-ubuntu-latest/* artifacts/artifacts-windows-latest/* artifacts/artifacts-macos-latest/* - draft: true env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From ce0c2776a29a8b31a57cb38a1427e69bf0639a25 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Fri, 28 Mar 2025 23:44:05 -0400 Subject: [PATCH 08/20] Updated artifact names for os --- .github/workflows/package-build.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/package-build.yaml b/.github/workflows/package-build.yaml index d18a909b..d7e7e524 100644 --- a/.github/workflows/package-build.yaml +++ b/.github/workflows/package-build.yaml @@ -15,9 +15,9 @@ jobs: - os: ubuntu-latest artifact_name: linux - os: windows-latest - artifact_name: win.exe + artifact_name: win32.exe - os: macos-latest - artifact_name: macos + artifact_name: darwin steps: - uses: actions/checkout@v4 From 5e4e253895d58c2d6f394ba3f96dedbfb89a01a9 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Sat, 29 Mar 2025 14:54:00 -0400 Subject: [PATCH 09/20] Change workflow to building the python package (#503) --- .github/workflows/package-build.yaml | 71 ++++++---------------------- 1 file changed, 14 insertions(+), 57 deletions(-) diff --git a/.github/workflows/package-build.yaml b/.github/workflows/package-build.yaml index d7e7e524..ade9de22 100644 --- a/.github/workflows/package-build.yaml +++ b/.github/workflows/package-build.yaml @@ -27,15 +27,17 @@ jobs: python-version: "3.10" architecture: ${{ runner.os == 'Windows' && 'x64' || '' }} - - name: Install tools + - name: Install build tools run: | python -m pip install --upgrade pip - pip install pyinstaller + pip install build pyinstaller - - name: Install package + - name: Build Python package run: | - pip install . - + python -m build + mkdir -p dist_python + mv dist/*.whl dist/*.tar.gz dist_python/ 2>/dev/null || true + - name: Create Linux executable if: matrix.os == 'ubuntu-latest' run: | @@ -70,52 +72,7 @@ jobs: pyinstaller --onefile --name ecooptimizer-server-dev $(which eco-ext-dev) mv dist/ecooptimizer-server-dev dist/ecooptimizer-server-dev-${{ matrix.artifact_name }} - - name: Install signing tools - if: matrix.os == 'windows-latest' - run: | - choco install osslsigncode -y - - - name: Sign Windows binaries - if: matrix.os == 'windows-latest' - shell: pwsh - run: | - # Generate cert - openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -subj "/CN=EcoOptimizer" - - # Sign in-place using temporary file - $TempFile = "dist\temp-signed.exe" - osslsigncode sign -certs cert.pem -key key.pem -n "EcoOptimizer" ` - -t http://timestamp.digicert.com ` - -in "dist\ecooptimizer-server-${{ matrix.artifact_name }}" ` - -out $TempFile - Move-Item -Path $TempFile -Destination "dist\ecooptimizer-server-${{ matrix.artifact_name }}" -Force - - osslsigncode sign -certs cert.pem -key key.pem -n "EcoOptimizer" ` - -t http://timestamp.digicert.com ` - -in "dist\ecooptimizer-server-dev-${{ matrix.artifact_name }}" ` - -out $TempFile - Move-Item -Path $TempFile -Destination "dist\ecooptimizer-server-dev-${{ matrix.artifact_name }}" -Force - - - name: Sign macOS binaries - if: matrix.os == 'macos-latest' - run: | - codesign --force --deep --sign - dist/ecooptimizer-server-${{ matrix.artifact_name }} - codesign --force --deep --sign - dist/ecooptimizer-server-dev-${{ matrix.artifact_name }} - - - name: Set up GPG (Linux) - if: matrix.os == 'ubuntu-latest' - run: | - sudo apt-get install -y gpg - echo "${{ secrets.GPG_PRIVATE_KEY }}" | gpg --batch --import - gpg --list-secret-keys - - - name: Sign Linux binaries - if: matrix.os == 'ubuntu-latest' - run: | - cd dist - gpg --batch --yes --detach-sign --armor -u "${{ secrets.GPG_KEY_ID }}" ecooptimizer-server-${{ matrix.artifact_name }} - gpg --batch --yes --detach-sign --armor -u "${{ secrets.GPG_KEY_ID }}" ecooptimizer-server-dev-${{ matrix.artifact_name }} - + # Upload both Python package artifacts and executables - name: Upload artifacts uses: actions/upload-artifact@v4 with: @@ -123,7 +80,8 @@ jobs: path: | dist/ecooptimizer-server-* dist/ecooptimizer-server-dev-* - dist/*.asc + dist_python/*.whl + dist_python/*.tar.gz if-no-files-found: error create-release: @@ -145,13 +103,12 @@ jobs: body: | ${{ github.event.head_commit.message }} - **Signed Artifacts:** - - Windows: Authenticode-signed - - macOS: Ad-hoc signed - - Linux: GPG-signed (.asc files) + **Artifacts:** + - Python package: .whl and .tar.gz files + - Executables for Windows, macOS, and Linux files: | artifacts/artifacts-ubuntu-latest/* artifacts/artifacts-windows-latest/* artifacts/artifacts-macos-latest/* env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From 668cf4397f709800004019c264ede5ba6c8e56fa Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Sat, 29 Mar 2025 14:54:54 -0400 Subject: [PATCH 10/20] changed stuff for testing the workflow --- .github/workflows/package-build.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/package-build.yaml b/.github/workflows/package-build.yaml index ade9de22..d047486e 100644 --- a/.github/workflows/package-build.yaml +++ b/.github/workflows/package-build.yaml @@ -2,8 +2,7 @@ name: Build and Release on: push: - tags: - - "v*" + branches: [build-sign-test] jobs: build: @@ -110,5 +109,6 @@ jobs: artifacts/artifacts-ubuntu-latest/* artifacts/artifacts-windows-latest/* artifacts/artifacts-macos-latest/* + draft: true env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file From bbb2ad00708b23f464fac4684bfb03ac8acb0572 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Sat, 29 Mar 2025 15:01:56 -0400 Subject: [PATCH 11/20] Added back in the package install step --- .github/workflows/package-build.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/package-build.yaml b/.github/workflows/package-build.yaml index d047486e..8bbe6795 100644 --- a/.github/workflows/package-build.yaml +++ b/.github/workflows/package-build.yaml @@ -31,6 +31,10 @@ jobs: python -m pip install --upgrade pip pip install build pyinstaller + - name: Install package + run: | + pip install . + - name: Build Python package run: | python -m build From 1d569576acf772aae7e07199a51755e6430a2431 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Sat, 29 Mar 2025 15:10:06 -0400 Subject: [PATCH 12/20] fixed bug --- .github/workflows/package-build.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/package-build.yaml b/.github/workflows/package-build.yaml index 8bbe6795..7d4280d2 100644 --- a/.github/workflows/package-build.yaml +++ b/.github/workflows/package-build.yaml @@ -39,7 +39,11 @@ jobs: run: | python -m build mkdir -p dist_python - mv dist/*.whl dist/*.tar.gz dist_python/ 2>/dev/null || true + if [[ "$RUNNER_OS" == "Windows" ]]; then + mv dist/*.whl dist/*.tar.gz dist_python/ 2>NUL || true + else + mv dist/*.whl dist/*.tar.gz dist_python/ 2>/dev/null || true + fi - name: Create Linux executable if: matrix.os == 'ubuntu-latest' From d7d01ae12e3ecf55147e03fa65ed3c11d42fda83 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Sat, 29 Mar 2025 15:16:34 -0400 Subject: [PATCH 13/20] and again --- .github/workflows/package-build.yaml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/package-build.yaml b/.github/workflows/package-build.yaml index 7d4280d2..42686efc 100644 --- a/.github/workflows/package-build.yaml +++ b/.github/workflows/package-build.yaml @@ -39,11 +39,8 @@ jobs: run: | python -m build mkdir -p dist_python - if [[ "$RUNNER_OS" == "Windows" ]]; then - mv dist/*.whl dist/*.tar.gz dist_python/ 2>NUL || true - else - mv dist/*.whl dist/*.tar.gz dist_python/ 2>/dev/null || true - fi + mv dist/*.whl dist_python/ + mv dist/*.tar.gz dist_python/ || true - name: Create Linux executable if: matrix.os == 'ubuntu-latest' From bf70a9d22fdcad67383e669fba84de86cad82ad3 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Sat, 29 Mar 2025 15:29:27 -0400 Subject: [PATCH 14/20] again --- .github/workflows/package-build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/package-build.yaml b/.github/workflows/package-build.yaml index 42686efc..8bef89d3 100644 --- a/.github/workflows/package-build.yaml +++ b/.github/workflows/package-build.yaml @@ -103,7 +103,7 @@ jobs: uses: softprops/action-gh-release@v1 with: tag_name: ${{ github.ref }} - name: ${{ github.ref_name }} + name: ${{ github.ref_name }} Test 1 body: | ${{ github.event.head_commit.message }} From d59e1bb2a9a3f36990de7d3498a475cf2669d7b4 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Sat, 29 Mar 2025 15:43:22 -0400 Subject: [PATCH 15/20] more fixes --- .github/workflows/package-build.yaml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.github/workflows/package-build.yaml b/.github/workflows/package-build.yaml index 8bef89d3..bffa8918 100644 --- a/.github/workflows/package-build.yaml +++ b/.github/workflows/package-build.yaml @@ -16,7 +16,7 @@ jobs: - os: windows-latest artifact_name: win32.exe - os: macos-latest - artifact_name: darwin + artifact_name: macos steps: - uses: actions/checkout@v4 @@ -38,9 +38,8 @@ jobs: - name: Build Python package run: | python -m build - mkdir -p dist_python - mv dist/*.whl dist_python/ - mv dist/*.tar.gz dist_python/ || true + mv dist/*.whl dist/ + mv dist/*.tar.gz dist/ || true - name: Create Linux executable if: matrix.os == 'ubuntu-latest' @@ -84,8 +83,8 @@ jobs: path: | dist/ecooptimizer-server-* dist/ecooptimizer-server-dev-* - dist_python/*.whl - dist_python/*.tar.gz + dist/*.whl + dist/*.tar.gz if-no-files-found: error create-release: From 221b328a38be70382b9933e8283adc0ad8a50461 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Sat, 29 Mar 2025 15:47:49 -0400 Subject: [PATCH 16/20] another fix --- .github/workflows/package-build.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/package-build.yaml b/.github/workflows/package-build.yaml index bffa8918..e302df56 100644 --- a/.github/workflows/package-build.yaml +++ b/.github/workflows/package-build.yaml @@ -38,8 +38,6 @@ jobs: - name: Build Python package run: | python -m build - mv dist/*.whl dist/ - mv dist/*.tar.gz dist/ || true - name: Create Linux executable if: matrix.os == 'ubuntu-latest' From b5b0ac21bd65608c8028f25e20f4cb60a84af58b Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Sat, 29 Mar 2025 18:16:21 -0400 Subject: [PATCH 17/20] publishing to PyPI (#503) --- .github/workflows/package-build.yaml | 37 ++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/.github/workflows/package-build.yaml b/.github/workflows/package-build.yaml index e302df56..82763dcf 100644 --- a/.github/workflows/package-build.yaml +++ b/.github/workflows/package-build.yaml @@ -29,16 +29,12 @@ jobs: - name: Install build tools run: | python -m pip install --upgrade pip - pip install build pyinstaller + pip install pyinstaller - name: Install package run: | pip install . - - name: Build Python package - run: | - python -m build - - name: Create Linux executable if: matrix.os == 'ubuntu-latest' run: | @@ -73,7 +69,6 @@ jobs: pyinstaller --onefile --name ecooptimizer-server-dev $(which eco-ext-dev) mv dist/ecooptimizer-server-dev dist/ecooptimizer-server-dev-${{ matrix.artifact_name }} - # Upload both Python package artifacts and executables - name: Upload artifacts uses: actions/upload-artifact@v4 with: @@ -81,13 +76,35 @@ jobs: path: | dist/ecooptimizer-server-* dist/ecooptimizer-server-dev-* - dist/*.whl - dist/*.tar.gz if-no-files-found: error - create-release: + publish-pypi: needs: build runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: "3.10" + - name: Install build tools + run: | + python -m pip install --upgrade pip + pip install build twine + - name: Build source distribution + run: | + python -m build + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + packages-dir: dist/ + env: + TWINE_USERNAME: __token__ + TWINE_PASSWORD: 'something' + + create-release: + needs: [build, publish-pypi] + runs-on: ubuntu-latest steps: - name: Download all artifacts uses: actions/download-artifact@v4 @@ -105,7 +122,7 @@ jobs: ${{ github.event.head_commit.message }} **Artifacts:** - - Python package: .whl and .tar.gz files + - Source distribution (.tar.gz) published to PyPI - Executables for Windows, macOS, and Linux files: | artifacts/artifacts-ubuntu-latest/* From e290b503229f155ecf2b3d6417833f004ba7c73a Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Sat, 29 Mar 2025 18:17:00 -0400 Subject: [PATCH 18/20] adjusted pyproject.toml for publishing (#503) --- pyproject.toml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 25181b22..a917c517 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,9 @@ [build-system] -requires = ["setuptools >= 61.0"] +requires = ["setuptools >= 61.0", "setuptools_scm[toml]>=6.0"] build-backend = "setuptools.build_meta" [project] name = "ecooptimizer" -version = "0.0.1" dependencies = [ "pylint", "rope", @@ -47,10 +46,12 @@ eco-ext = "ecooptimizer.api.__main__:main" eco-ext-dev = "ecooptimizer.api.__main__:dev" [project.urls] -Documentation = "https://readthedocs.org" Repository = "https://github.com/ssm-lab/capstone--source-code-optimizer" "Bug Tracker" = "https://github.com/ssm-lab/capstone--source-code-optimizer/issues" +[tool.setuptools_scm] +write_to = "your_package/_version.py" + [tool.pytest.ini_options] norecursedirs = ["tests/temp*", "tests/input", "tests/_input_copies"] addopts = ["--basetemp=tests/temp_dir"] From 55b9b0695f119e22df6abd23f52a0783b31976bd Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Sat, 29 Mar 2025 18:50:57 -0400 Subject: [PATCH 19/20] fixes --- .gitignore | 4 +++- pyproject.toml | 13 ++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 3f8602fe..2f612c51 100644 --- a/.gitignore +++ b/.gitignore @@ -307,4 +307,6 @@ tests/benchmarking/output/ # Coverage .coverage -coverage.* \ No newline at end of file +coverage.* + +src/ecooptimizer/_version.py \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index a917c517..b13e0b75 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,6 +16,7 @@ dependencies = [ "libcst", "websockets", ] +version = "0.1.0" requires-python = ">=3.9" authors = [ { name = "Sevhena Walker" }, @@ -50,7 +51,17 @@ Repository = "https://github.com/ssm-lab/capstone--source-code-optimizer" "Bug Tracker" = "https://github.com/ssm-lab/capstone--source-code-optimizer/issues" [tool.setuptools_scm] -write_to = "your_package/_version.py" +write_to = "src/ecooptimizer/_version.py" +fallback_version = "0.1.0" + +[tool.setuptools] +packages = ["ecooptimizer"] + +[tool.setuptools.package-dir] +ecooptimizer = "src/ecooptimizer" + +[tool.setuptools.exclude-package-data] +"*" = ["docs/*", "tests/*", ".github/*"] [tool.pytest.ini_options] norecursedirs = ["tests/temp*", "tests/input", "tests/_input_copies"] From 2a313f02ef1e218a6bea890196e94ad514856236 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Sat, 29 Mar 2025 19:08:51 -0400 Subject: [PATCH 20/20] Fixes + final workflow Fixed api entrypoint options entry fixes #503 --- .github/workflows/package-build.yaml | 5 +++-- src/ecooptimizer/api/__main__.py | 18 ++++++++++++------ src/ecooptimizer/api/error_handler.py | 6 +----- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.github/workflows/package-build.yaml b/.github/workflows/package-build.yaml index 82763dcf..94281391 100644 --- a/.github/workflows/package-build.yaml +++ b/.github/workflows/package-build.yaml @@ -2,7 +2,8 @@ name: Build and Release on: push: - branches: [build-sign-test] + tags: + - "v*" jobs: build: @@ -100,7 +101,7 @@ jobs: packages-dir: dist/ env: TWINE_USERNAME: __token__ - TWINE_PASSWORD: 'something' + TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }} create-release: needs: [build, publish-pypi] diff --git a/src/ecooptimizer/api/__main__.py b/src/ecooptimizer/api/__main__.py index 08bb0e6d..160d3efb 100644 --- a/src/ecooptimizer/api/__main__.py +++ b/src/ecooptimizer/api/__main__.py @@ -1,7 +1,7 @@ """Application entry point and server configuration for EcoOptimizer.""" +import argparse import logging -import sys import uvicorn from ecooptimizer.api.app import app @@ -27,7 +27,7 @@ def filter(self, record: logging.LogRecord) -> bool: logging.getLogger("uvicorn.access").addFilter(HealthCheckFilter()) -def start(): +def start(host: str = "127.0.0.1", port: int = 8000): """Starts the Uvicorn server with configured settings. Displays startup banner and handles different run modes. @@ -52,8 +52,8 @@ def start(): uvicorn.run( app, - host="127.0.0.1", - port=8000, + host=host, + port=port, log_level="info", access_log=True, timeout_graceful_shutdown=2, @@ -62,8 +62,14 @@ def start(): def main(): """Main entry point that sets mode based on command line arguments.""" - CONFIG["mode"] = "development" if "--dev" in sys.argv else "production" - start() + parser = argparse.ArgumentParser() + parser.add_argument("--dev", action="store_true", help="Run in development mode") + parser.add_argument("--port", type=int, default=8000, help="Port to run on") + parser.add_argument("--host", default="127.0.0.1", help="Host to bind to") + args = parser.parse_args() + + CONFIG["mode"] = "development" if args.dev else "production" + start(args.host, args.port) def dev(): diff --git a/src/ecooptimizer/api/error_handler.py b/src/ecooptimizer/api/error_handler.py index e29b0d56..75d8b5d1 100644 --- a/src/ecooptimizer/api/error_handler.py +++ b/src/ecooptimizer/api/error_handler.py @@ -2,7 +2,6 @@ import logging import os import stat -import traceback from fastapi import Request from fastapi.responses import JSONResponse @@ -69,10 +68,7 @@ async def global_error_handler(request: Request, e: Exception) -> JSONResponse: content={"detail": e.message}, ) else: - logger.error( - f"Unexpected error at {request.url.path}\n" - f"{''.join(traceback.format_exception(type(e), e, e.__traceback__))}" - ) + logger.error(f"Unexpected error at {request.url.path}", e) return JSONResponse( status_code=500, content={"detail": "Internal server error"},