Run GitHub Actions in PRs too #23
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: Docker | |
on: | |
push: | |
branches: | |
- main | |
tags: | |
- v* | |
pull_request: | |
jobs: | |
docker: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Prepare configuration | |
run: | | |
REF_NAME=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | |
VERSION= | |
# Strip "v" prefix from tag name | |
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $REF_NAME | sed -e 's/^v//') | |
# Use Docker `latest` tag convention | |
[[ "${{ github.ref }}" == "refs/heads/main" ]] && VERSION=latest | |
# Use commit hash otherwise | |
[[ -z "$VERSION" ]] && VERSION=${{ github.sha }} | |
echo VERSION=$VERSION | |
echo "VERSION=${VERSION}" >> $GITHUB_ENV | |
IMAGE_ID=${{ github.repository_owner }}/latex | |
echo IMAGE_ID=$IMAGE_ID | |
echo "IMAGE_ID=${IMAGE_ID}" >> $GITHUB_ENV | |
- name: Build minimal | |
run: | | |
make minimal | |
- name: Build basic | |
run: | | |
make basic | |
- name: Build small | |
run: | | |
make small | |
- name: Build medium | |
run: | | |
make medium | |
- name: Build full | |
run: | | |
make full | |
- name: Run tests | |
run: | | |
make test | |
- name: Log in to DockerHub | |
uses: docker/login-action@v2 | |
if: github.ref == 'refs/heads/main' | |
with: | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Log in to GitHub Container Registry | |
uses: docker/login-action@v2 | |
if: github.ref == 'refs/heads/main' | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Push images | |
if: github.ref == 'refs/heads/main' | |
run: | | |
docker push ${{ env.IMAGE_ID }}:${{ env.VERSION }}-minimal | |
docker push ${{ env.IMAGE_ID }}:${{ env.VERSION }}-basic | |
docker push ${{ env.IMAGE_ID }}:${{ env.VERSION }}-small | |
docker push ${{ env.IMAGE_ID }}:${{ env.VERSION }}-medium | |
docker push ${{ env.IMAGE_ID }}:${{ env.VERSION }}-full | |
docker push ${{ env.IMAGE_ID }}:${{ env.VERSION }} | |
docker tag ${{ env.IMAGE_ID }}:${{ env.IMAGE_ID }}-minimal ghcr.io/${{ env.IMAGE_ID }}:${{ env.VERSION }}-minimal | |
docker tag ${{ env.IMAGE_ID }}:${{ env.IMAGE_ID }}-basic ghcr.io/${{ env.IMAGE_ID }}:${{ env.VERSION }}-basic | |
docker tag ${{ env.IMAGE_ID }}:${{ env.IMAGE_ID }}-small ghcr.io/${{ env.IMAGE_ID }}:${{ env.VERSION }}-small | |
docker tag ${{ env.IMAGE_ID }}:${{ env.IMAGE_ID }}-medium ghcr.io/${{ env.IMAGE_ID }}:${{ env.VERSION }}-medium | |
docker tag ${{ env.IMAGE_ID }}:${{ env.IMAGE_ID }}-full ghcr.io/${{ env.IMAGE_ID }}:${{ env.VERSION }}-full | |
docker tag ${{ env.IMAGE_ID }}:${{ env.IMAGE_ID }} ghcr.io/${{ env.IMAGE_ID }}:${{ env.VERSION }} | |
docker push ghcr.io/${{ env.IMAGE_ID }}:${{ env.VERSION }}-minimal | |
docker push ghcr.io/${{ env.IMAGE_ID }}:${{ env.VERSION }}-basic | |
docker push ghcr.io/${{ env.IMAGE_ID }}:${{ env.VERSION }}-small | |
docker push ghcr.io/${{ env.IMAGE_ID }}:${{ env.VERSION }}-medium | |
docker push ghcr.io/${{ env.IMAGE_ID }}:${{ env.VERSION }}-full | |
docker push ghcr.io/${{ env.IMAGE_ID }}:${{ env.VERSION }} |