Auto-update Convox CLI #149
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
| name: Auto-update Convox CLI | |
| on: | |
| schedule: | |
| - cron: "0 8 * * *" # Daily at 8 AM UTC | |
| workflow_dispatch: # Allow manual trigger | |
| permissions: | |
| contents: write | |
| jobs: | |
| check-and-update: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| update: ${{ steps.check.outputs.update }} | |
| version: ${{ steps.version.outputs.new_version }} | |
| convox_version: ${{ steps.convox.outputs.version }} | |
| convox_sha256: ${{ steps.checksum.outputs.sha256 }} | |
| steps: | |
| - name: Get latest Convox release | |
| id: convox | |
| run: | | |
| LATEST=$(curl -sf https://api.github.com/repos/convox/convox/releases/latest | jq -r '.tag_name') | |
| if [ -z "$LATEST" ] || [ "$LATEST" = "null" ]; then | |
| echo "::error::Failed to fetch latest Convox release" | |
| exit 1 | |
| fi | |
| echo "version=$LATEST" >> "$GITHUB_OUTPUT" | |
| echo "Latest Convox release: $LATEST" | |
| - name: Compute checksum for new release | |
| id: checksum | |
| run: | | |
| LATEST="${{ steps.convox.outputs.version }}" | |
| SHA=$(curl -fsSL --retry 3 "https://github.com/convox/convox/releases/download/${LATEST}/convox-linux" | sha256sum | awk '{print $1}') | |
| if ! echo "$SHA" | grep -qE '^[0-9a-f]{64}$'; then | |
| echo "::error::Failed to compute checksum for convox ${LATEST}" | |
| exit 1 | |
| fi | |
| echo "sha256=$SHA" >> "$GITHUB_OUTPUT" | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Check if update needed | |
| id: check | |
| run: | | |
| CURRENT=$(cat CONVOX_VERSION 2>/dev/null | tr -d '[:space:]' || echo "none") | |
| LATEST="${{ steps.convox.outputs.version }}" | |
| echo "Current tracked version: $CURRENT" | |
| echo "Latest Convox version: $LATEST" | |
| if [ "$CURRENT" = "$LATEST" ]; then | |
| echo "Already up to date." | |
| echo "update=false" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "New version available!" | |
| echo "update=true" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Bump patch version | |
| if: steps.check.outputs.update == 'true' | |
| id: version | |
| run: | | |
| CURRENT_VERSION=$(cat VERSION | tr -d '[:space:]') | |
| VERSION_NUM="${CURRENT_VERSION#v}" | |
| BASE_VERSION=$(echo "$VERSION_NUM" | grep -oE '^[0-9]+\.[0-9]+\.[0-9]+') | |
| MAJOR=$(echo "$BASE_VERSION" | cut -d. -f1) | |
| MINOR=$(echo "$BASE_VERSION" | cut -d. -f2) | |
| PATCH=$(echo "$BASE_VERSION" | cut -d. -f3) | |
| NEW_PATCH=$((PATCH + 1)) | |
| NEW_VERSION="v${MAJOR}.${MINOR}.${NEW_PATCH}" | |
| echo "Bumping $CURRENT_VERSION -> $NEW_VERSION" | |
| echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT" | |
| release: | |
| needs: check-and-update | |
| if: needs.check-and-update.outputs.update == 'true' | |
| uses: ./.github/workflows/build-and-release.yml | |
| with: | |
| version: ${{ needs.check-and-update.outputs.version }} | |
| commit-message: "Auto-update Convox CLI to ${{ needs.check-and-update.outputs.convox_version }} (${{ needs.check-and-update.outputs.version }})" | |
| convox-version: ${{ needs.check-and-update.outputs.convox_version }} | |
| convox-sha256: ${{ needs.check-and-update.outputs.convox_sha256 }} | |
| summary: | |
| needs: [check-and-update, release] | |
| if: needs.check-and-update.outputs.update == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Summary | |
| run: | | |
| echo "### Convox CLI Auto-Update" >> "$GITHUB_STEP_SUMMARY" | |
| echo "" >> "$GITHUB_STEP_SUMMARY" | |
| echo "- **Convox version:** ${{ needs.check-and-update.outputs.convox_version }}" >> "$GITHUB_STEP_SUMMARY" | |
| echo "- **Action version:** ${{ needs.check-and-update.outputs.version }}" >> "$GITHUB_STEP_SUMMARY" |