diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3cee359 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,26 @@ +name: CI + +on: + pull_request: + branches: [main] + push: + branches: [main] + +permissions: + contents: read + +jobs: + build: + # Confirms the Dockerfile still builds. + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: docker/setup-buildx-action@v3 + + - uses: docker/build-push-action@v5 + with: + context: . + push: false + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..0f2c1cf --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,77 @@ +name: Publish image + +on: + push: + tags: ['v*'] + public: + workflow_dispatch: + +permissions: + contents: read + packages: write + +env: + IMAGE: ghcr.io/action-prediction-lab/pepper-box + +jobs: + publish-tag: + # On a tag push to a public repo: build and push that one tag plus :latest. + # On a private repo: this job is skipped; the tag still exists in git. + if: | + github.event_name == 'push' && + github.event.repository.private == false + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: docker/setup-buildx-action@v3 + + - uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: | + ${{ env.IMAGE }}:${{ github.ref_name }} + ${{ env.IMAGE }}:latest + cache-from: type=gha + cache-to: type=gha,mode=max + + backfill: + # On private->public flip or manual re-run: build every existing v* tag. + if: github.event_name == 'public' || github.event_name == 'workflow_dispatch' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push each existing v* tag + run: | + set -euo pipefail + tags=$(git tag --list 'v*' --sort=creatordate) + if [[ -z "$tags" ]]; then + echo "No v* tags found, nothing to backfill." + exit 0 + fi + for tag in $tags; do + echo "::group::$tag" + git checkout "$tag" + docker build -t "$IMAGE:$tag" . + docker push "$IMAGE:$tag" + echo "::endgroup::" + done + latest=$(echo "$tags" | tail -1) + docker tag "$IMAGE:$latest" "$IMAGE:latest" + docker push "$IMAGE:latest"