From 49ee4a636a024662d7002c1b3375fddbb301cbe8 Mon Sep 17 00:00:00 2001 From: Mark Saroufim Date: Wed, 7 May 2025 09:21:40 -0700 Subject: [PATCH 1/3] Automate release --- .github/release.yml | 113 ++++++++++++++++++++++++++++++++++++ .github/workflows/build.yml | 29 ++++++++- 2 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 .github/release.yml diff --git a/.github/release.yml b/.github/release.yml new file mode 100644 index 0000000..d5416cd --- /dev/null +++ b/.github/release.yml @@ -0,0 +1,113 @@ +# .github/workflows/release.yml +name: Release Popcorn CLI + +on: + push: + tags: + - 'v*' # Trigger on tags like v0.1.0, v1.2.3 + +permissions: + contents: write # Needed to create releases and upload assets + +jobs: + # Job 1: Build binaries for different targets + build: + name: Build for ${{ matrix.target }} + strategy: + fail-fast: false # Don't cancel all builds if one fails + matrix: + include: + # Linux x86_64 + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + binary_name: popcorn-cli # Name of the executable in target/release + asset_name: popcorn-cli-linux-amd64.tar.gz # Name for the release file + # macOS x86_64 + - os: macos-latest + target: x86_64-apple-darwin + binary_name: popcorn-cli + asset_name: popcorn-cli-macos-amd64.tar.gz + # macOS arm64 (Apple Silicon) + - os: macos-latest # Can cross-compile or use native runner if available + target: aarch64-apple-darwin + binary_name: popcorn-cli + asset_name: popcorn-cli-macos-arm64.tar.gz + # Windows x86_64 + - os: windows-latest + target: x86_64-pc-windows-msvc + binary_name: popcorn-cli.exe # Note the .exe extension + asset_name: popcorn-cli-windows-amd64.zip + + runs-on: ${{ matrix.os }} + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Rust toolchain + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + target: ${{ matrix.target }} + toolchain: stable + + - name: Build binary + # Ensure we build in the correct sub-directory + working-directory: popcorn-cli/rust + run: cargo build --verbose --release --target ${{ matrix.target }} + + - name: Package (Linux/macOS) + if: runner.os != 'Windows' + # Path to binary is relative to the repo root: popcorn-cli/rust/target//release/ + # We create the archive in the repo root. + run: | + BINARY_PATH="popcorn-cli/rust/target/${{ matrix.target }}/release/${{ matrix.binary_name }}" + tar czvf "${{ matrix.asset_name }}" -C "$(dirname "$BINARY_PATH")" "$(basename "$BINARY_PATH")" + shell: bash + + - name: Package (Windows) + if: runner.os == 'Windows' + # Path to binary is relative to the repo root + run: | + Compress-Archive -Path "popcorn-cli/rust/target/${{ matrix.target }}/release/${{ matrix.binary_name }}" -DestinationPath "${{ matrix.asset_name }}" + shell: pwsh + + - name: Upload artifact for release job + # Upload the packaged archive, using the desired final asset name + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.asset_name }} # Use asset name as artifact name + path: ${{ matrix.asset_name }} # Path to the created archive at the repo root + if-no-files-found: error # Fail if archive wasn't created + + # Job 2: Create GitHub Release and Upload Binaries + release: + name: Create GitHub Release + needs: build # Run after all build jobs succeed + runs-on: ubuntu-latest + # Only run on tag pushes + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + + steps: + # Download all artifacts. Since artifact names match asset names, they are ready for upload. + # download-artifact@v4 downloads them into the current directory without extra subdirs by default + # if no 'path' is specified and multiple artifacts are downloaded. + - name: Download all release artifacts + uses: actions/download-artifact@v4 + # No 'path' means download all artifacts to the current directory. + # Artifacts were named like 'popcorn-cli-linux-amd64.tar.gz', so they'll be downloaded with those names. + + # Optional: List files to verify downloads + # - name: List downloaded artifacts + # run: ls -l + + - name: Create Release and Upload Assets + uses: softprops/action-gh-release@v2 + with: + # Use the tag name (e.g., "v0.1.0") for the release + tag_name: ${{ github.ref_name }} + # Automatically generate release notes from commits since the last tag + generate_release_notes: true + # Upload all the downloaded files (archives) + # The wildcard '*' picks up all files downloaded in the previous step. + files: | + *.tar.gz + *.zip \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4f23522..79ff9ce 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,7 +2,9 @@ name: release on: push: - # Sequence of patterns matched against refs/tags + branches: + - main + # Keep existing tag trigger tags: - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 @@ -14,8 +16,27 @@ permissions: contents: write jobs: + version: + name: Generate Version + runs-on: ubuntu-latest + outputs: + version: ${{ steps.version.outputs.version }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Generate Version + id: version + uses: mathieudutour/github-tag-action@v6.1 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + default_bump: patch + release_branches: main + build: name: Build + needs: version runs-on: ${{ matrix.os }} strategy: matrix: @@ -86,9 +107,9 @@ jobs: release: name: Create Release - needs: build + needs: [build, version] runs-on: ubuntu-latest - if: startsWith(github.ref, 'refs/tags/') + if: startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/main' steps: - name: Download all artifacts @@ -97,6 +118,8 @@ jobs: - name: Create Release uses: softprops/action-gh-release@v1 with: + tag_name: v${{ needs.version.outputs.version }} + name: Release v${{ needs.version.outputs.version }} files: | popcorn-cli-linux.tar.gz/popcorn-cli-linux.tar.gz popcorn-cli-windows.zip/popcorn-cli-windows.zip From d3e8bbc4b926c0861310cc3628a79b863bea3a76 Mon Sep 17 00:00:00 2001 From: Mark Saroufim Date: Wed, 7 May 2025 09:27:06 -0700 Subject: [PATCH 2/3] update --- .github/release.yml | 113 -------------------------------------------- 1 file changed, 113 deletions(-) delete mode 100644 .github/release.yml diff --git a/.github/release.yml b/.github/release.yml deleted file mode 100644 index d5416cd..0000000 --- a/.github/release.yml +++ /dev/null @@ -1,113 +0,0 @@ -# .github/workflows/release.yml -name: Release Popcorn CLI - -on: - push: - tags: - - 'v*' # Trigger on tags like v0.1.0, v1.2.3 - -permissions: - contents: write # Needed to create releases and upload assets - -jobs: - # Job 1: Build binaries for different targets - build: - name: Build for ${{ matrix.target }} - strategy: - fail-fast: false # Don't cancel all builds if one fails - matrix: - include: - # Linux x86_64 - - os: ubuntu-latest - target: x86_64-unknown-linux-gnu - binary_name: popcorn-cli # Name of the executable in target/release - asset_name: popcorn-cli-linux-amd64.tar.gz # Name for the release file - # macOS x86_64 - - os: macos-latest - target: x86_64-apple-darwin - binary_name: popcorn-cli - asset_name: popcorn-cli-macos-amd64.tar.gz - # macOS arm64 (Apple Silicon) - - os: macos-latest # Can cross-compile or use native runner if available - target: aarch64-apple-darwin - binary_name: popcorn-cli - asset_name: popcorn-cli-macos-arm64.tar.gz - # Windows x86_64 - - os: windows-latest - target: x86_64-pc-windows-msvc - binary_name: popcorn-cli.exe # Note the .exe extension - asset_name: popcorn-cli-windows-amd64.zip - - runs-on: ${{ matrix.os }} - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up Rust toolchain - uses: actions-rust-lang/setup-rust-toolchain@v1 - with: - target: ${{ matrix.target }} - toolchain: stable - - - name: Build binary - # Ensure we build in the correct sub-directory - working-directory: popcorn-cli/rust - run: cargo build --verbose --release --target ${{ matrix.target }} - - - name: Package (Linux/macOS) - if: runner.os != 'Windows' - # Path to binary is relative to the repo root: popcorn-cli/rust/target//release/ - # We create the archive in the repo root. - run: | - BINARY_PATH="popcorn-cli/rust/target/${{ matrix.target }}/release/${{ matrix.binary_name }}" - tar czvf "${{ matrix.asset_name }}" -C "$(dirname "$BINARY_PATH")" "$(basename "$BINARY_PATH")" - shell: bash - - - name: Package (Windows) - if: runner.os == 'Windows' - # Path to binary is relative to the repo root - run: | - Compress-Archive -Path "popcorn-cli/rust/target/${{ matrix.target }}/release/${{ matrix.binary_name }}" -DestinationPath "${{ matrix.asset_name }}" - shell: pwsh - - - name: Upload artifact for release job - # Upload the packaged archive, using the desired final asset name - uses: actions/upload-artifact@v4 - with: - name: ${{ matrix.asset_name }} # Use asset name as artifact name - path: ${{ matrix.asset_name }} # Path to the created archive at the repo root - if-no-files-found: error # Fail if archive wasn't created - - # Job 2: Create GitHub Release and Upload Binaries - release: - name: Create GitHub Release - needs: build # Run after all build jobs succeed - runs-on: ubuntu-latest - # Only run on tag pushes - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') - - steps: - # Download all artifacts. Since artifact names match asset names, they are ready for upload. - # download-artifact@v4 downloads them into the current directory without extra subdirs by default - # if no 'path' is specified and multiple artifacts are downloaded. - - name: Download all release artifacts - uses: actions/download-artifact@v4 - # No 'path' means download all artifacts to the current directory. - # Artifacts were named like 'popcorn-cli-linux-amd64.tar.gz', so they'll be downloaded with those names. - - # Optional: List files to verify downloads - # - name: List downloaded artifacts - # run: ls -l - - - name: Create Release and Upload Assets - uses: softprops/action-gh-release@v2 - with: - # Use the tag name (e.g., "v0.1.0") for the release - tag_name: ${{ github.ref_name }} - # Automatically generate release notes from commits since the last tag - generate_release_notes: true - # Upload all the downloaded files (archives) - # The wildcard '*' picks up all files downloaded in the previous step. - files: | - *.tar.gz - *.zip \ No newline at end of file From ceb2e7160294d980c31f612c2104345a727f6e4f Mon Sep 17 00:00:00 2001 From: Mark Saroufim Date: Wed, 7 May 2025 10:24:13 -0700 Subject: [PATCH 3/3] remove comment --- .github/workflows/build.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 79ff9ce..f4eba0c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,6 @@ on: push: branches: - main - # Keep existing tag trigger tags: - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10