|
| 1 | +name: Rollback Latest Tags to Version |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: "Version to rollback to (e.g. 2.8.0)" |
| 8 | + required: true |
| 9 | + type: string |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + |
| 14 | +jobs: |
| 15 | + rollback: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + permissions: |
| 18 | + packages: write |
| 19 | + steps: |
| 20 | + - name: Harden Runner |
| 21 | + uses: step-security/harden-runner@58077d3c7e43986b6b15fba718e8ea69e387dfcc # v2.15.1 |
| 22 | + with: |
| 23 | + egress-policy: audit |
| 24 | + |
| 25 | + - name: Install crane |
| 26 | + uses: imjasonh/setup-crane@31b88afe9de28ae0ffa220711af4b60be9435f6e # v0.4 |
| 27 | + |
| 28 | + - name: Login to Docker Hub |
| 29 | + uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0 |
| 30 | + with: |
| 31 | + username: ${{ secrets.DOCKER_HUB_USERNAME }} |
| 32 | + password: ${{ secrets.DOCKER_HUB_API }} |
| 33 | + |
| 34 | + - name: Login to GitHub Container Registry |
| 35 | + uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0 |
| 36 | + with: |
| 37 | + registry: ghcr.io |
| 38 | + username: ${{ github.actor }} |
| 39 | + password: ${{ github.token }} |
| 40 | + |
| 41 | + - name: Convert repository owner to lowercase |
| 42 | + id: repoowner |
| 43 | + run: echo "lowercase=$(echo ${{ github.repository_owner }} | awk '{print tolower($0)}')" >> $GITHUB_OUTPUT |
| 44 | + |
| 45 | + - name: Rollback all latest tags to v${{ inputs.version }} |
| 46 | + env: |
| 47 | + VERSION: ${{ inputs.version }} |
| 48 | + DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} |
| 49 | + DOCKER_HUB_ORG_USERNAME: ${{ secrets.DOCKER_HUB_ORG_USERNAME }} |
| 50 | + REPO_OWNER: ${{ steps.repoowner.outputs.lowercase }} |
| 51 | + run: | |
| 52 | + set -euo pipefail |
| 53 | +
|
| 54 | + IMAGES=( |
| 55 | + "${DOCKER_HUB_USERNAME}/s-pdf" |
| 56 | + "ghcr.io/${REPO_OWNER}/s-pdf" |
| 57 | + "ghcr.io/${REPO_OWNER}/stirling-pdf" |
| 58 | + "${DOCKER_HUB_ORG_USERNAME}/stirling-pdf" |
| 59 | + ) |
| 60 | +
|
| 61 | + VARIANTS=( |
| 62 | + "${VERSION}:latest" |
| 63 | + "${VERSION}-fat:latest-fat" |
| 64 | + "${VERSION}-ultra-lite:latest-ultra-lite" |
| 65 | + ) |
| 66 | +
|
| 67 | + FAILED=0 |
| 68 | +
|
| 69 | + for image in "${IMAGES[@]}"; do |
| 70 | + for variant in "${VARIANTS[@]}"; do |
| 71 | + SOURCE_TAG="${variant%%:*}" |
| 72 | + TARGET_TAG="${variant##*:}" |
| 73 | +
|
| 74 | + echo "::group::${image} — ${SOURCE_TAG} → ${TARGET_TAG}" |
| 75 | +
|
| 76 | + if crane manifest "${image}:${SOURCE_TAG}" > /dev/null 2>&1; then |
| 77 | + crane cp "${image}:${SOURCE_TAG}" "${image}:${TARGET_TAG}" |
| 78 | + echo "✅ ${image}:${TARGET_TAG} now points to ${SOURCE_TAG}" |
| 79 | + else |
| 80 | + echo "::warning::⚠️ ${image}:${SOURCE_TAG} not found, skipping" |
| 81 | + FAILED=1 |
| 82 | + fi |
| 83 | +
|
| 84 | + echo "::endgroup::" |
| 85 | + done |
| 86 | + done |
| 87 | +
|
| 88 | + if [ "$FAILED" -ne 0 ]; then |
| 89 | + echo "::warning::Some source tags were not found. This is expected if not all variants exist for this version." |
| 90 | + fi |
| 91 | +
|
| 92 | + echo "" |
| 93 | + echo "🎉 Rollback to ${VERSION} complete!" |
0 commit comments