Skip to content

Commit

Permalink
add ghcr workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
rxu17 committed Oct 18, 2024
1 parent 3a18ae8 commit 39fbb71
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/build-docker-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Build and Push Docker Images

on:
push:
branches: [develop, 'GEN*', 'gen*']
paths:
- 'scripts/references/**'
- '.github/workflows/build-docker-images.yml'
workflow_dispatch:

jobs:
build_references_docker:
runs-on: ubuntu-latest
env:
REGISTRY: ghcr.io
IMAGE_NAME: sage-bionetworks/genie-bpc-pipeline
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 2

- name: Setup Docker buildx
uses: docker/setup-buildx-action@v3

- name: Fetch the default branch (develop) for comparison
run: git fetch origin develop:refs/remotes/origin/develop --depth=1

- name: Check for Changes in scripts/references
id: check_changes
run: |
# Check for a merge base, fallback to root commit if none exists
if git merge-base --is-ancestor origin/develop HEAD; then
DIFF_BASE="origin/develop"
else
DIFF_BASE=$(git rev-list --max-parents=0 HEAD) # Use the initial commit as fallback
fi
# Compare changes between DIFF_BASE and HEAD
if git diff --name-only $DIFF_BASE -- scripts/references | grep -q .; then
echo "CHANGED=true" >> $GITHUB_ENV
else
echo "CHANGED=false" >> $GITHUB_ENV
fi
- name: Log in to GitHub Container Registry
if: env.CHANGED == 'true'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Push Docker Image for scripts/references
if: env.CHANGED == 'true'
uses: docker/build-push-action@v5
with:
context: scripts/references
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:references-${{ github.ref_name }}
cache-from: type=registry,ref=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:references-${{ github.ref_name }}-cache
cache-to: type=inline,mode=max

0 comments on commit 39fbb71

Please sign in to comment.