changes (detect paths + calculate version)

|
build [cargo, docker]  (parallel matrix)
|
update-manifests (bump Cargo.toml, commit, tag)
|
release (GitHub release + checksums)
This commit is contained in:
Harivansh Rathi 2026-03-25 16:54:11 -04:00
parent 4bd14c0da3
commit a6ea5cc9e8

View file

@ -15,12 +15,16 @@ permissions:
jobs: jobs:
changes: changes:
name: Detect Changes name: Changes
runs-on: ubuntu-latest runs-on: ubuntu-latest
outputs: outputs:
rust: ${{ steps.check.outputs.rust }} rust: ${{ steps.check.outputs.rust }}
version: ${{ steps.version.outputs.version }}
tag: ${{ steps.version.outputs.tag }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: dorny/paths-filter@v3 - uses: dorny/paths-filter@v3
id: filter id: filter
@ -41,21 +45,9 @@ jobs:
echo "rust=${{ steps.filter.outputs.rust }}" >> "$GITHUB_OUTPUT" echo "rust=${{ steps.filter.outputs.rust }}" >> "$GITHUB_OUTPUT"
fi fi
version:
name: Next Version
needs: changes
if: needs.changes.outputs.rust == 'true'
runs-on: ubuntu-latest
outputs:
version: ${{ steps.next.outputs.version }}
tag: ${{ steps.next.outputs.tag }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Calculate next version - name: Calculate next version
id: next id: version
if: steps.check.outputs.rust == 'true'
run: | run: |
BASE=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/') BASE=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/')
IFS='.' read -r MAJOR MINOR PATCH <<< "$BASE" IFS='.' read -r MAJOR MINOR PATCH <<< "$BASE"
@ -74,65 +66,72 @@ jobs:
echo "version=${NEW}" >> "$GITHUB_OUTPUT" echo "version=${NEW}" >> "$GITHUB_OUTPUT"
echo "tag=v${NEW}" >> "$GITHUB_OUTPUT" echo "tag=v${NEW}" >> "$GITHUB_OUTPUT"
cargo: build:
name: Build and Test name: Build (${{ matrix.target }})
needs: [changes, version] needs: changes
if: needs.changes.outputs.rust == 'true' if: needs.changes.outputs.rust == 'true'
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
target: [cargo, docker]
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
# --- Cargo steps ---
- uses: dtolnay/rust-toolchain@stable - uses: dtolnay/rust-toolchain@stable
if: matrix.target == 'cargo'
with: with:
components: clippy components: clippy
- uses: Swatinem/rust-cache@v2 - uses: Swatinem/rust-cache@v2
if: matrix.target == 'cargo'
- name: Install system dependencies - name: Install system dependencies
if: matrix.target == 'cargo'
run: sudo apt-get update && sudo apt-get install -y libx11-dev libxtst-dev run: sudo apt-get update && sudo apt-get install -y libx11-dev libxtst-dev
- name: Clippy - name: Clippy
if: matrix.target == 'cargo'
run: cargo clippy -- -D warnings run: cargo clippy -- -D warnings
- name: Build - name: Build
if: matrix.target == 'cargo'
run: cargo build --release --locked run: cargo build --release --locked
- uses: actions/upload-artifact@v4 - uses: actions/upload-artifact@v4
if: matrix.target == 'cargo'
with: with:
name: deskctl-linux-x86_64 name: deskctl-linux-x86_64
path: target/release/deskctl path: target/release/deskctl
retention-days: 7 retention-days: 7
docker: # --- Docker steps ---
name: Docker
needs: [changes, version, cargo]
if: needs.changes.outputs.rust == 'true'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: docker/setup-buildx-action@v3 - uses: docker/setup-buildx-action@v3
if: matrix.target == 'docker'
- uses: docker/login-action@v3 - uses: docker/login-action@v3
if: matrix.target == 'docker'
with: with:
registry: ghcr.io registry: ghcr.io
username: ${{ github.actor }} username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v6 - uses: docker/build-push-action@v6
if: matrix.target == 'docker'
with: with:
context: . context: .
file: docker/Dockerfile file: docker/Dockerfile
push: true push: true
tags: | tags: |
ghcr.io/${{ github.repository }}:latest ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:${{ needs.version.outputs.tag }} ghcr.io/${{ github.repository }}:${{ needs.changes.outputs.tag }}
cache-from: type=gha cache-from: type=gha
cache-to: type=gha,mode=max cache-to: type=gha,mode=max
update-manifests: update-manifests:
name: Update Manifests name: Update Manifests
needs: [version, cargo, docker] needs: [changes, build]
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
@ -144,7 +143,7 @@ jobs:
- name: Update version in Cargo.toml - name: Update version in Cargo.toml
run: | run: |
CURRENT=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/') CURRENT=$(grep '^version' Cargo.toml | head -1 | sed 's/.*"\(.*\)"/\1/')
NEW="${{ needs.version.outputs.version }}" NEW="${{ needs.changes.outputs.version }}"
if [ "$CURRENT" != "$NEW" ]; then if [ "$CURRENT" != "$NEW" ]; then
sed -i "0,/^version = \"${CURRENT}\"/s//version = \"${NEW}\"/" Cargo.toml sed -i "0,/^version = \"${CURRENT}\"/s//version = \"${NEW}\"/" Cargo.toml
cargo generate-lockfile cargo generate-lockfile
@ -157,15 +156,15 @@ jobs:
if ! git diff --quiet; then if ! git diff --quiet; then
git add Cargo.toml Cargo.lock git add Cargo.toml Cargo.lock
git commit -m "release: ${{ needs.version.outputs.tag }} [skip ci]" git commit -m "release: ${{ needs.changes.outputs.tag }} [skip ci]"
fi fi
git tag "${{ needs.version.outputs.tag }}" git tag "${{ needs.changes.outputs.tag }}"
git push origin main --tags git push origin main --tags
release: release:
name: Release name: Release
needs: [version, cargo, update-manifests] needs: [changes, build, update-manifests]
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
@ -183,8 +182,8 @@ jobs:
mv artifacts/deskctl artifacts/deskctl-linux-x86_64 mv artifacts/deskctl artifacts/deskctl-linux-x86_64
cd artifacts && sha256sum deskctl-linux-x86_64 > checksums.txt && cd .. cd artifacts && sha256sum deskctl-linux-x86_64 > checksums.txt && cd ..
gh release create "${{ needs.version.outputs.tag }}" \ gh release create "${{ needs.changes.outputs.tag }}" \
--title "${{ needs.version.outputs.tag }}" \ --title "${{ needs.changes.outputs.tag }}" \
--generate-notes \ --generate-notes \
artifacts/deskctl-linux-x86_64 \ artifacts/deskctl-linux-x86_64 \
artifacts/checksums.txt artifacts/checksums.txt