From f3ffb224871920dad52867f247225feddb988b7c Mon Sep 17 00:00:00 2001 From: Cody Seibert Date: Sat, 13 Dec 2025 00:46:24 -0500 Subject: [PATCH] testing releases --- .github/scripts/upload-to-r2.js | 68 ++++++++++++++++++++++++++++++++- .github/workflows/release.yml | 27 ++++++++++++- 2 files changed, 92 insertions(+), 3 deletions(-) diff --git a/.github/scripts/upload-to-r2.js b/.github/scripts/upload-to-r2.js index 67940265..71d3a80d 100644 --- a/.github/scripts/upload-to-r2.js +++ b/.github/scripts/upload-to-r2.js @@ -5,6 +5,8 @@ const { } = require("@aws-sdk/client-s3"); const fs = require("fs"); const path = require("path"); +const https = require("https"); +const { pipeline } = require("stream/promises"); const s3Client = new S3Client({ region: "auto", @@ -18,6 +20,7 @@ const s3Client = new S3Client({ const BUCKET = process.env.R2_BUCKET_NAME; const PUBLIC_URL = process.env.R2_PUBLIC_URL; const VERSION = process.env.RELEASE_VERSION; +const RELEASE_TAG = process.env.RELEASE_TAG || `v${VERSION}`; const GITHUB_REPO = process.env.GITHUB_REPOSITORY; async function fetchExistingReleases() { @@ -62,8 +65,60 @@ function findArtifacts(dir, pattern) { return files.filter((f) => pattern.test(f)).map((f) => path.join(dir, f)); } +async function downloadFromGitHub(url, outputPath) { + return new Promise((resolve, reject) => { + https + .get(url, (response) => { + if (response.statusCode === 302 || response.statusCode === 301) { + // Follow redirect + return downloadFromGitHub(response.headers.location, outputPath) + .then(resolve) + .catch(reject); + } + if (response.statusCode !== 200) { + reject( + new Error( + `Failed to download ${url}: ${response.statusCode} ${response.statusMessage}` + ) + ); + return; + } + const fileStream = fs.createWriteStream(outputPath); + response.pipe(fileStream); + fileStream.on("finish", () => { + fileStream.close(); + resolve(); + }); + fileStream.on("error", reject); + }) + .on("error", reject); + }); +} + async function main() { const artifactsDir = "artifacts"; + const tempDir = path.join(artifactsDir, "temp"); + + // Create temp directory for downloaded GitHub archives + if (!fs.existsSync(tempDir)) { + fs.mkdirSync(tempDir, { recursive: true }); + } + + // Download source archives from GitHub + const githubZipUrl = `https://github.com/${GITHUB_REPO}/archive/refs/tags/${RELEASE_TAG}.zip`; + const githubTarGzUrl = `https://github.com/${GITHUB_REPO}/archive/refs/tags/${RELEASE_TAG}.tar.gz`; + + const sourceZipPath = path.join(tempDir, `automaker-${VERSION}.zip`); + const sourceTarGzPath = path.join(tempDir, `automaker-${VERSION}.tar.gz`); + + console.log(`Downloading source archives from GitHub...`); + console.log(` ZIP: ${githubZipUrl}`); + console.log(` TAR.GZ: ${githubTarGzUrl}`); + + await downloadFromGitHub(githubZipUrl, sourceZipPath); + await downloadFromGitHub(githubTarGzUrl, sourceTarGzPath); + + console.log(`Downloaded source archives successfully`); // Find all artifacts const artifacts = { @@ -77,6 +132,8 @@ async function main() { path.join(artifactsDir, "linux-builds"), /\.AppImage$/ ), + sourceZip: [sourceZipPath], + sourceTarGz: [sourceTarGzPath], }; console.log("Found artifacts:"); @@ -97,6 +154,8 @@ async function main() { macos: "application/x-apple-diskimage", macosArm: "application/x-apple-diskimage", linux: "application/x-executable", + sourceZip: "application/zip", + sourceTarGz: "application/gzip", }; for (const [platform, files] of Object.entries(artifacts)) { @@ -115,7 +174,12 @@ async function main() { url: `${PUBLIC_URL}/releases/${VERSION}/${filename}`, filename, size, - arch: platform === "macosArm" ? "arm64" : "x64", + arch: + platform === "macosArm" + ? "arm64" + : platform === "sourceZip" || platform === "sourceTarGz" + ? "source" + : "x64", }; } @@ -126,7 +190,7 @@ async function main() { version: VERSION, date: new Date().toISOString(), assets, - githubReleaseUrl: `https://github.com/${GITHUB_REPO}/releases/tag/${VERSION}`, + githubReleaseUrl: `https://github.com/${GITHUB_REPO}/releases/tag/${RELEASE_TAG}`, }; // Remove existing entry for this version if re-running diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 11abdcd3..396736ef 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -48,6 +48,20 @@ jobs: # optional dependencies (e.g., @tailwindcss/oxide, lightningcss binaries) run: npm install + - name: Extract and set version + id: version + run: | + VERSION_TAG="${{ github.event.inputs.version || github.ref_name }}" + # Remove 'v' prefix if present (e.g., v1.0.0 -> 1.0.0) + VERSION="${VERSION_TAG#v}" + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "Extracted version: $VERSION from tag: $VERSION_TAG" + # Update the app's package.json version + cd apps/app + npm version $VERSION --no-git-tag-version + cd ../.. + echo "Updated apps/app/package.json to version $VERSION" + - name: Build Electron App (macOS) if: matrix.os == 'macos-latest' env: @@ -127,6 +141,16 @@ jobs: - name: Install AWS SDK run: npm install @aws-sdk/client-s3 + - name: Extract version + id: version + run: | + VERSION_TAG="${{ github.event.inputs.version || github.ref_name }}" + # Remove 'v' prefix if present (e.g., v1.0.0 -> 1.0.0) + VERSION="${VERSION_TAG#v}" + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "version_tag=$VERSION_TAG" >> $GITHUB_OUTPUT + echo "Extracted version: $VERSION from tag: $VERSION_TAG" + - name: Upload to R2 and update releases.json env: R2_ENDPOINT: ${{ secrets.R2_ENDPOINT }} @@ -134,6 +158,7 @@ jobs: R2_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }} R2_BUCKET_NAME: ${{ secrets.R2_BUCKET_NAME }} R2_PUBLIC_URL: ${{ secrets.R2_PUBLIC_URL }} - RELEASE_VERSION: ${{ github.event.inputs.version || github.ref_name }} + RELEASE_VERSION: ${{ steps.version.outputs.version }} + RELEASE_TAG: ${{ steps.version.outputs.version_tag }} GITHUB_REPOSITORY: ${{ github.repository }} run: node .github/scripts/upload-to-r2.js