Build and Push Docker Images #268
This file contains 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: Build and Push Docker Images | |
on: | |
push: | |
branches: | |
- "main" | |
schedule: | |
- cron: "0 0 * * *" | |
workflow_dispatch: | |
permissions: | |
contents: write | |
jobs: | |
build-push: | |
name: Build and Push ${{ matrix.release_type }} Docker Images | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
release_type: ["latest", "pre-release"] | |
steps: | |
- name: Checkout branch | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ github.head_ref }} | |
- name: Check latest Pocketbase Version | |
run: | | |
if [ "${{ matrix.release_type }}" = "latest" ]; then | |
curl -s https://api.github.com/repos/pocketbase/pocketbase/releases | jq -r '.[] | select(.prerelease == false and .draft == false) | .tag_name' | head -n 1 | sed 's/^v//' > latest_version | |
else | |
curl -s https://api.github.com/repos/pocketbase/pocketbase/releases | jq -r '.[] | select(.prerelease == true and .draft == false) | .tag_name' | head -n 1 | sed 's/^v//' > latest_version | |
fi | |
echo "LATEST_VERSION=$(cat latest_version)" >> $GITHUB_ENV | |
id: latest_version | |
- name: Print Pocketbase Version | |
run: | | |
cat latest_version | |
echo "The current ${{ matrix.release_type }} pocketbase version is ${{ env.LATEST_VERSION }}" | |
id: print_version | |
- name: Check latest ${{ matrix.release_type }} Docker Image Version | |
run: | | |
echo "LATEST_DOCKER_VERSION=default_version" >> $GITHUB_ENV | |
docker pull lukehagar/pocketbase:${{ matrix.release_type }} | |
docker inspect lukehagar/pocketbase:${{ matrix.release_type }} --format='{{index .Config.Labels "org.opencontainers.image.version"}}' > latest_docker_version | |
echo "LATEST_DOCKER_VERSION=$(cat latest_docker_version)" >> $GITHUB_ENV | |
id: latest_docker_version | |
continue-on-error: true | |
- name: Print latest ${{ matrix.release_type }} Docker Image Version | |
run: | | |
echo "The current ${{ matrix.release_type }} docker version is ${{ env.LATEST_DOCKER_VERSION }}" | |
id: print_docker_version | |
- name: Check if latest version is different | |
id: check_version | |
run: | | |
if [ "${{env.LATEST_VERSION}}" != "${{env.LATEST_DOCKER_VERSION}}" ]; then | |
echo "Versions are different" | |
echo "BUILD=true" >> $GITHUB_OUTPUT | |
else | |
echo "Versions are the same" | |
echo "BUILD=false" >> $GITHUB_OUTPUT | |
fi | |
- name: Set up QEMU | |
if: steps.check_version.outputs.build == 'true' | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
if: steps.check_version.outputs.build == 'true' | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to Docker Hub | |
if: steps.check_version.outputs.build == 'true' | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push | |
if: steps.check_version.outputs.build == 'true' | |
uses: docker/build-push-action@v5 | |
with: | |
push: true | |
tags: lukehagar/pocketbase:${{ matrix.release_type }} | |
build-args: POCKETBASE_VERSION=${{ env.LATEST_VERSION }} | |
- name: Update Changelog | |
run: | | |
curl -s https://raw.githubusercontent.com/pocketbase/pocketbase/master/CHANGELOG.md > CHANGELOG.md | |
- name: Commit and push | |
uses: stefanzweifel/git-auto-commit-action@v4 | |
with: | |
commit_message: Update changelog for ${{ env.LATEST_VERSION }} |