Create a simple preview build of journal on GitHub actions when one of two preview-* tags are applied to a PR elifesciences/issues#9051 #5
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: Pull Request Preview Environment | |
on: | |
pull_request: | |
types: [labeled, unlabeled, synchronize, opened, reopened] | |
jobs: | |
generate-date: | |
runs-on: ubuntu-latest | |
outputs: | |
date: ${{ steps.date.outputs.date }} | |
steps: | |
- name: Get current date | |
id: date | |
run: echo "date=$(date --utc +%Y%m%d.%H%M)" >> $GITHUB_OUTPUT | |
build-preview-image: | |
runs-on: ubuntu-latest | |
needs: [generate-date] | |
if: ${{ contains(github.event.pull_request.labels.*.name, 'preview-prod-gateway') || contains(github.event.pull_request.labels.*.name, 'preview-api-dummy') }} | |
env: | |
CONTAINER_REPO: ghcr.io/elifesciences/journal | |
CONTAINER_TAG: preview-${{ github.event.number }}-${{ github.event.pull_request.head.sha }}-${{ needs.generate-date.outputs.date }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Login to GHCR | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build container image | |
run: | | |
docker compose -f 'docker-compose.yml' -f 'docker-compose.ci.yml' build | |
docker image tag elifesciences/journal:develop ${CONTAINER_REPO}:${CONTAINER_TAG} | |
- name: Push container image | |
run: docker push ${CONTAINER_REPO}:${CONTAINER_TAG} |