diff --git a/.github/workflows/on-pr-docker-cleanup.yml b/.github/workflows/on-pr-docker-cleanup.yml new file mode 100644 index 000000000..c390d635e --- /dev/null +++ b/.github/workflows/on-pr-docker-cleanup.yml @@ -0,0 +1,58 @@ +name: "[PR] Cleanup Docker preview image" + +on: + pull_request: + types: [closed] + branches: + - dev + +permissions: + packages: write + +env: + REGISTRY: ghcr.io + IMAGE_TAG: omar-test-pr-${{ github.event.number }} + +jobs: + delete-image: + name: Delete PR preview image from GHCR + runs-on: ubuntu-latest + timeout-minutes: 5 + steps: + - name: Delete package version + uses: actions/github-script@v8 + with: + script: | + const packageName = 'homarr'; + const org = context.repo.owner; + const tag = process.env.IMAGE_TAG; + + const versions = await github.paginate( + github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg, + { + package_type: 'container', + package_name: packageName, + org, + per_page: 100, + } + ); + + const target = versions.find(v => + v.metadata?.container?.tags?.includes(tag) + ); + + if (!target) { + console.log(`No package version found with tag "${tag}". Nothing to delete.`); + return; + } + + console.log(`Deleting package version ${target.id} (tag: ${tag})`); + + await github.rest.packages.deletePackageVersionForOrg({ + package_type: 'container', + package_name: packageName, + org, + package_version_id: target.id, + }); + + console.log(`Successfully deleted package version ${target.id}`); diff --git a/.github/workflows/on-pr-docker-publish.yml b/.github/workflows/on-pr-docker-publish.yml new file mode 100644 index 000000000..b42312a52 --- /dev/null +++ b/.github/workflows/on-pr-docker-publish.yml @@ -0,0 +1,60 @@ +name: "[PR] Publish Docker preview image" + +on: + pull_request: + types: [opened, synchronize, reopened] + branches: + - dev + +permissions: + packages: write + +env: + SKIP_ENV_VALIDATION: true + REGISTRY: ghcr.io + GHCR_REPO: ghcr.io/${{ github.repository }} + TURBO_TELEMETRY_DISABLED: 1 + +concurrency: + group: pr-docker-${{ github.event.number }} + cancel-in-progress: true + +jobs: + build-and-push: + name: Build and push PR preview image + runs-on: ubuntu-latest + timeout-minutes: 20 + steps: + - uses: actions/checkout@v6 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v6 + with: + images: "${{ env.GHCR_REPO }}" + tags: | + type=raw,value=omar-test-pr-${{ github.event.number }} + + - name: Log in to the Container registry + uses: docker/login-action@v4 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v4 + + - name: Build and push + uses: docker/build-push-action@v7 + with: + context: . + network: host + platforms: linux/amd64 + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + push: true + cache-from: type=gha + cache-to: type=gha,mode=max + env: + SKIP_ENV_VALIDATION: true