Skip to content

Commit

Permalink
Try script for upload built and signed artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyb3r-Jak3 committed Apr 24, 2024
1 parent 7cc3775 commit e7705f2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 7 deletions.
27 changes: 27 additions & 0 deletions .github/upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""Upload the artifacts to Cloudflare R2 Storage"""

import os
import boto3

BUCKET_NAME = os.getenv("BUCKET_NAME", "pypy-files")
PYPY_VERSION = os.environ["PYPY_VERSION"]

s3 = boto3.resource(
's3',
endpoint_url='https://8be772befd147a8df540aae0fa15c047.r2.cloudflarestorage.com',
)


def upload_file(file_name: str) -> None:
"""Uploads a file to R2"""
try:
s3.upload_file(file_name, BUCKET_NAME, f"pypy/{PYPY_VERSION}/{file_name}")
except Exception as e:
print(f"Failed to upload {file_name} to {file_name}: {e}")
raise e
print(f"Uploaded {file_name}")


if __name__ == "__main__":
for file in os.listdir("./output"):
upload_file(file)
40 changes: 33 additions & 7 deletions .github/workflows/build-pypy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ permissions:
env:
ALPINE_VERSION: 3.19
BUILDER_IMAGE_TAG: ghcr.io/cyb3r-jak3/alpine-pypy-builder-workflow
PYPY_VERSION: 7.3.16

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down Expand Up @@ -63,7 +64,6 @@ jobs:
fail-fast: true
matrix:
PYPY_BASE: ["2.7", "3.9", "3.10"]
PYPY_VERSION: ["7.3.16"]
RUNNER: ["self-hosted", "ubuntu-latest"]

steps:
Expand All @@ -89,7 +89,7 @@ jobs:
run: |
import os
import requests
base_url = "https://pypy.cyberjake.xyz/pypy/${{ matrix.PYPY_BASE }}/pypy${{ matrix.PYPY_BASE }}-v${{ matrix.PYPY_VERSION }}-linux-${{ env.PYPY_ARCH }}-alpine.tar.bz2"
base_url = "https://pypy.cyberjake.xyz/pypy/${{ matrix.PYPY_BASE }}/pypy${{ matrix.PYPY_BASE }}-v${{ env.PYPY_VERSION }}-linux-${{ env.PYPY_ARCH }}-alpine.tar.bz2"
file_resp = requests.head(base_url)
signature_resp = requests.head(f"{base_url}.sig")
if file_resp.status_code == 404 or signature_resp.status_code == 404:
Expand All @@ -115,9 +115,9 @@ jobs:
- name: Run Build
if: steps.file-check.outputs.STATUS == 404
run: |
PYPY_SHA256SUM=$(curl -s https://api.cyberjake.xyz/pypy/checksums/pypy${{ matrix.PYPY_BASE }}-v${{ matrix.PYPY_VERSION }}-src.tar.bz2 | jq --raw-output .results[0].checksum)
PYPY_SHA256SUM=$(curl -s https://api.cyberjake.xyz/pypy/checksums/pypy${{ matrix.PYPY_BASE }}-v${{ env.PYPY_VERSION }}-src.tar.bz2 | jq --raw-output .results[0].checksum)
echo "${PYPY_SHA256SUM}"
docker run --platform linux/${{ env.ARCH }} -v $(pwd)/tmp:/tmp -e PYPY_BASE=${{ matrix.PYPY_BASE }} -e PYPY_VERSION=${{ matrix.PYPY_VERSION }} -e PYPY_SHA256SUM="${PYPY_SHA256SUM}" ${{ env.BUILDER_IMAGE_TAG }}:${{ env.ALPINE_VERSION }}-${{ github.sha }}
docker run --platform linux/${{ env.ARCH }} -v $(pwd)/tmp:/tmp -e PYPY_BASE=${{ matrix.PYPY_BASE }} -e PYPY_VERSION=${{ env.PYPY_VERSION }} -e PYPY_SHA256SUM="${PYPY_SHA256SUM}" ${{ env.BUILDER_IMAGE_TAG }}:${{ env.ALPINE_VERSION }}-${{ github.sha }}
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@v6
Expand All @@ -132,19 +132,45 @@ jobs:
run: |
wget --quiet -O sign.py https://raw.githubusercontent.com/Cyb3r-Jak3/docker-alpine-pypy/${{ github.sha }}/.github/sign.py
mkdir output
mv ./tmp/usession-release-pypy${{ matrix.PYPY_BASE }}-v${{ matrix.PYPY_VERSION }}-*/build/**.tar.bz2 ./output/pypy${{ matrix.PYPY_BASE }}-v${{ matrix.PYPY_VERSION }}-linux-${{ env.PYPY_ARCH }}-alpine.tar.bz2
mv ./tmp/usession-release-pypy${{ matrix.PYPY_BASE }}-v${{ env.PYPY_VERSION }}-*/build/**.tar.bz2 ./output/pypy${{ matrix.PYPY_BASE }}-v${{ env.PYPY_VERSION }}-linux-${{ env.PYPY_ARCH }}-alpine.tar.bz2
find ./output/ -type f -exec python3 sign.py {} \;
- name: Upload PyPy to Artifacts
if: steps.file-check.outputs.STATUS == 404
# Leave with v3 so we can use the same name for the artifact
uses: actions/upload-artifact@v4
with:
name: pypy-${{ env.ARCH }}-${{ matrix.PYPY_BASE }}-${{ matrix.PYPY_VERSION }}
name: pypy-${{ env.ARCH }}-${{ matrix.PYPY_BASE }}-${{ env.PYPY_VERSION }}
path: ./output

- name: Clean files
if: steps.file-check.outputs.STATUS == 404
run: |
rm -rf output/
rm -rf tmp/
Upload:
runs-on: ubuntu-latest
name: Upload PyPy builds
needs: Build

steps:
- name: Download upload script
run: |
wget --quiet -O upload.py https://raw.githubusercontent.com/Cyb3r-Jak3/docker-alpine-pypy/${{ github.sha }}/.github/upload.py
pip install boto3==1.34.90
- name: Download PyPy builds
uses: actions/download-artifact@v4
with:
pattern: 'pypy-*'
merge-multiple: true
path: ./output

- name: Upload PyPy builds
run: |
python .github/upload.py
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

0 comments on commit e7705f2

Please sign in to comment.