-
Notifications
You must be signed in to change notification settings - Fork 1
Add automated release CI pipeline and update project scripts #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,294 @@ | ||
| name: Create Release and Packages | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| tag_name: | ||
| description: 'Tag name for the release (e.g. v0.1.0)' | ||
| required: true | ||
| type: string | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.event.inputs.tag_name }} | ||
| cancel-in-progress: false | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| build-binaries: | ||
| name: Build Binaries | ||
| runs-on: ${{ matrix.os }} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| include: | ||
| - target: x86_64-unknown-linux-gnu | ||
| os: ubuntu-latest | ||
| use_cross: false | ||
| bin_suffix: "" | ||
| bin_name: kdc | ||
| - target: aarch64-unknown-linux-gnu | ||
| os: ubuntu-latest | ||
| use_cross: true | ||
| bin_suffix: "" | ||
| bin_name: kdc | ||
| - target: x86_64-apple-darwin | ||
| os: macos-latest | ||
| use_cross: false | ||
| bin_suffix: "" | ||
| bin_name: kdc | ||
| - target: aarch64-apple-darwin | ||
| os: macos-latest | ||
| use_cross: false | ||
| bin_suffix: "" | ||
| bin_name: kdc | ||
| - target: x86_64-pc-windows-msvc | ||
| os: windows-latest | ||
| use_cross: false | ||
| bin_suffix: ".exe" | ||
| bin_name: kdc.exe | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Install Rust toolchain | ||
| uses: dtolnay/rust-toolchain@a54c08fd6ec450103756d6dc20d2d48332156d7f # master | ||
| with: | ||
| targets: ${{ matrix.target }} | ||
|
|
||
| - name: Cache Cargo registry and target | ||
| uses: Swatinem/rust-cache@23bde28c093e9ae8b3b402174d994c9d924d0eb8 # v2.7.5 | ||
| with: | ||
| key: ${{ matrix.target }} | ||
|
|
||
| - name: Install cross | ||
| if: matrix.use_cross | ||
| uses: taiki-e/install-action@93a027fc80e60808cf702e5e4fa0eb13e01fccf2 # v2.1.20 | ||
| with: | ||
| tool: cross | ||
|
|
||
| - name: Build release binary | ||
| run: | | ||
| if [ "${{ matrix.use_cross }}" = "true" ]; then | ||
| cross build --release --target ${{ matrix.target }} | ||
| else | ||
| cargo build --release --target ${{ matrix.target }} | ||
| fi | ||
| shell: bash | ||
|
|
||
| - name: Upload Binary Artifact | ||
| uses: actions/upload-artifact@60119845307540294e774020a87424eeac47d7e6 # v4.4.1 | ||
| with: | ||
| name: kdc-${{ matrix.target }} | ||
| path: target/${{ matrix.target }}/release/${{ matrix.bin_name }} | ||
| retention-days: 1 | ||
|
|
||
| create-release: | ||
| name: Create Release | ||
| needs: build-binaries | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| outputs: | ||
| version: ${{ steps.get_version.outputs.version }} | ||
| tag_name: ${{ steps.get_version.outputs.tag_name }} | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Get version from input | ||
| id: get_version | ||
| env: | ||
| TAG_NAME: ${{ inputs.tag_name }} | ||
| run: | | ||
| # Strict regex check for semver tag starting with 'v' | ||
| if [[ ! "$TAG_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(?:[-+].*)?$ ]]; then | ||
| echo "Error: Tag name '$TAG_NAME' is invalid. It must match semver format with a leading 'v' (e.g., v1.0.0, v0.1.0-alpha.1)." >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| VERSION="${TAG_NAME#v}" | ||
| echo "version=${VERSION}" >> "$GITHUB_OUTPUT" | ||
| echo "tag_name=${TAG_NAME}" >> "$GITHUB_OUTPUT" | ||
| shell: bash | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| - name: Download all artifacts | ||
| uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372ec806f1c # v4.1.7 | ||
| with: | ||
| path: bin-artifacts | ||
|
|
||
| - name: Package archives and generate checksums | ||
| id: package | ||
| run: | | ||
| mkdir dist | ||
| cd bin-artifacts | ||
|
|
||
| for target_dir in ./kdc-*; do | ||
| target="${target_dir#./kdc-}" | ||
| echo "Packaging archive for $target..." | ||
|
|
||
| if [ -f "$target_dir/kdc.exe" ]; then | ||
| # Windows | ||
| zip -j "../dist/kdc-v${{ steps.get_version.outputs.version }}-${target}.zip" "$target_dir/kdc.exe" | ||
| else | ||
| # Unix | ||
| chmod +x "$target_dir/kdc" | ||
| tar -czf "../dist/kdc-v${{ steps.get_version.outputs.version }}-${target}.tar.gz" -C "$target_dir" kdc | ||
| fi | ||
| done | ||
|
|
||
| cd ../dist | ||
| sha256sum -- kdc-* > sha256sums.txt | ||
| cat sha256sums.txt | ||
| shell: bash | ||
|
|
||
| - name: Upload archives to release | ||
| uses: softprops/action-gh-release@c862437e9029c5496c3ae47d90ec96cac9521fd3 # v2.0.8 | ||
| with: | ||
| files: | | ||
| dist/* | ||
| tag_name: ${{ steps.get_version.outputs.tag_name }} | ||
| draft: false | ||
| prerelease: false | ||
| generate_release_notes: true | ||
|
|
||
| - name: Upload packaging artifacts | ||
| uses: actions/upload-artifact@60119845307540294e774020a87424eeac47d7e6 # v4.4.1 | ||
| with: | ||
| name: release-dist | ||
| path: dist/ | ||
| retention-days: 1 | ||
|
|
||
| generate-packages: | ||
| name: Generate Packages (APT, RPM, Homebrew) | ||
| needs: create-release | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Download release-dist artifact | ||
| uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372ec806f1c # v4.1.7 | ||
| with: | ||
| name: release-dist | ||
| path: dist | ||
|
|
||
| - name: Download compiled binaries | ||
| uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372ec806f1c # v4.1.7 | ||
| with: | ||
| path: bin-artifacts | ||
|
|
||
| - name: Generate APT and RPM packages | ||
| run: | | ||
| chmod +x scripts/package.sh | ||
| ./scripts/package.sh \ | ||
| "${{ needs.create-release.outputs.version }}" \ | ||
| "bin-artifacts/kdc-x86_64-unknown-linux-gnu/kdc" \ | ||
| "bin-artifacts/kdc-aarch64-unknown-linux-gnu/kdc" \ | ||
| "dist" | ||
| shell: bash | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| - name: Generate Homebrew Formula | ||
| id: generate_formula | ||
| run: | | ||
| VERSION="${{ needs.create-release.outputs.version }}" | ||
| SHA_MAC_AMD64=$(grep "kdc-v${VERSION}-x86_64-apple-darwin.tar.gz" dist/sha256sums.txt | awk '{print $1}') | ||
| SHA_MAC_ARM64=$(grep "kdc-v${VERSION}-aarch64-apple-darwin.tar.gz" dist/sha256sums.txt | awk '{print $1}') | ||
| SHA_LINUX_AMD64=$(grep "kdc-v${VERSION}-x86_64-unknown-linux-gnu.tar.gz" dist/sha256sums.txt | awk '{print $1}') | ||
| SHA_LINUX_ARM64=$(grep "kdc-v${VERSION}-aarch64-unknown-linux-gnu.tar.gz" dist/sha256sums.txt | awk '{print $1}') | ||
|
|
||
| cat <<EOF > dist/kdc.rb | ||
| class Kdc < Formula | ||
| desc "Kubernetes Docker Commander, a project-centric DevOps TUI" | ||
| homepage "https://github.com/${{ github.repository }}" | ||
| version "${VERSION}" | ||
|
|
||
| if OS.mac? | ||
| if Hardware::CPU.arm? | ||
| url "https://github.com/${{ github.repository }}/releases/download/v\${version}/kdc-v\${version}-aarch64-apple-darwin.tar.gz" | ||
| sha256 "${SHA_MAC_ARM64}" | ||
| else | ||
| url "https://github.com/${{ github.repository }}/releases/download/v\--version/kdc-v\${version}-x86_64-apple-darwin.tar.gz" | ||
| sha256 "${SHA_MAC_AMD64}" | ||
| end | ||
| elsif OS.linux? | ||
| if Hardware::CPU.arm? | ||
| url "https://github.com/${{ github.repository }}/releases/download/v\${version}/kdc-v\${version}-aarch64-unknown-linux-gnu.tar.gz" | ||
| sha256 "${SHA_LINUX_ARM64}" | ||
| else | ||
| url "https://github.com/${{ github.repository }}/releases/download/v\${version}/kdc-v\${version}-x86_64-unknown-linux-gnu.tar.gz" | ||
| sha256 "${SHA_LINUX_AMD64}" | ||
| end | ||
| end | ||
|
|
||
| def install | ||
| bin.install "kdc" | ||
| end | ||
|
|
||
| test do | ||
| system "\#{bin}/kdc", "--version" | ||
| end | ||
| end | ||
| EOF | ||
|
|
||
| # Fix target download URL for macOS Intel | ||
| sed -i "s/v\\\\--version/v\\\\\${version}/g" dist/kdc.rb | ||
|
|
||
| echo "Formula generated:" | ||
| cat dist/kdc.rb | ||
| shell: bash | ||
|
|
||
| - name: Update existing release with packages | ||
| uses: softprops/action-gh-release@c862437e9029c5496c3ae47d90ec96cac9521fd3 # v2.0.8 | ||
| with: | ||
| files: | | ||
| dist/*.deb | ||
| dist/*.rpm | ||
| dist/kdc.rb | ||
| tag_name: ${{ needs.create-release.outputs.tag_name }} | ||
| append_body: true | ||
|
|
||
| - name: Update Homebrew Tap Repository | ||
| env: | ||
| TAP_TOKEN: ${{ secrets.HOMEBREW_TAP_TOKEN }} | ||
| run: | | ||
| if [ -z "$TAP_TOKEN" ]; then | ||
| echo "Warning: HOMEBREW_TAP_TOKEN is not configured. Skipping automated Homebrew formula update." | ||
| echo "The generated Homebrew formula was uploaded as a release asset (kdc.rb)." | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "Configuring git..." | ||
| git config --global user.name "github-actions[bot]" | ||
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | ||
|
|
||
| GITHUB_REPO="${{ github.repository }}" | ||
| GITHUB_OWNER="${GITHUB_REPO%/*}" | ||
|
|
||
| echo "Cloning homebrew tap owned by ${GITHUB_OWNER}..." | ||
| git clone "https://${TAP_TOKEN}@github.com/${GITHUB_OWNER}/homebrew-tap.git" homebrew-tap | ||
|
|
||
| mkdir -p homebrew-tap/Formula | ||
| cp dist/kdc.rb homebrew-tap/Formula/kdc.rb | ||
|
|
||
| cd homebrew-tap | ||
| git add Formula/kdc.rb | ||
|
|
||
| if git diff-index --quiet HEAD; then | ||
| echo "No changes in Homebrew formula." | ||
| else | ||
| git commit -m "Bump kdc to v${{ needs.create-release.outputs.version }}" | ||
| git push origin main | ||
| echo "Successfully updated Homebrew Formula in tap." | ||
| fi | ||
| shell: bash | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.