Skip to content

Build PG253 images

Build PG253 images #15

Workflow file for this run

---
name: Build PG253 images
on:
# trigger every sunday morning
schedule:
- cron: "2 2 * * SUN"
# trigger on PR merge and push to main branch
push:
branches:
- main
# trigger on PR
pull_request:
types: [opened, reopened, synchronize, labeled]
branches:
- main
jobs:
build-and-push:
if: github.event_name == 'push' || github.event_name == 'schedule'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Log in to GitHub Container Registry
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Build and push to ghcr
run: |
docker build -t ghcr.io/camptocamp/pg253:latest \
--pull --no-cache \
--label GIT_COMMIT=$(git rev-parse HEAD) .
docker push ghcr.io/camptocamp/pg253:latest
TAG="$(git rev-parse --abbrev-ref HEAD)-$(git rev-parse --short HEAD)"
docker tag ghcr.io/camptocamp/pg253:latest ghcr.io/camptocamp/pg253:${TAG}
docker push ghcr.io/camptocamp/pg253:${TAG}
build-on-pr:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Log in to GitHub Container Registry
if: ${{ contains( github.event.pull_request.labels.*.name, 'build') }}
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: Build and push to ghcr
if: ${{ contains( github.event.pull_request.labels.*.name, 'build') }}
run: |
TAG="pr-${{ github.event.pull_request.number }}-$(git rev-parse --short HEAD)"
echo "TAG=${TAG}" >> $GITHUB_ENV
docker build -t ghcr.io/camptocamp/pg253:${TAG} \
--pull --no-cache \
--label GIT_COMMIT=$(git rev-parse HEAD) .
docker push ghcr.io/camptocamp/pg253:${TAG}
- name: Comment PR
uses: actions/github-script@v7
if: ${{ contains( github.event.pull_request.labels.*.name, 'build') }}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "A docker image was successfully build for your Pull Request: `ghcr.io/camptocamp/pg253:${{ env.TAG }}`"
})
- name: Build only
if: ${{ ! contains( github.event.pull_request.labels.*.name, 'build') }}
run: |
docker build --pull --no-cache .