|
| 1 | +name: Build |
| 2 | +on: |
| 3 | + push: |
| 4 | + workflow_dispatch: |
| 5 | +env: |
| 6 | + REGISTRY: ghcr.io |
| 7 | + IMAGE_NAME: ${{ github.repository }} |
| 8 | +jobs: |
| 9 | + docker-rebuild: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Checkout |
| 13 | + uses: actions/checkout@v2 |
| 14 | + with: |
| 15 | + fetch-depth: 0 |
| 16 | + |
| 17 | + - uses: dorny/paths-filter@v3 |
| 18 | + id: filter |
| 19 | + with: |
| 20 | + filters: | |
| 21 | + docker-rebuild: |
| 22 | + - 'Dockerfile' |
| 23 | +
|
| 24 | + - name: Log in to the Container registry |
| 25 | + if: steps.filter.outputs.docker-rebuild == 'true' |
| 26 | + uses: docker/login-action@v3.4.0 |
| 27 | + with: |
| 28 | + registry: ${{ env.REGISTRY }} |
| 29 | + username: ${{ github.actor }} |
| 30 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 31 | + |
| 32 | + - name: Extract metadata (tags, labels) for Docker |
| 33 | + if: steps.filter.outputs.docker-rebuild == 'true' |
| 34 | + id: meta |
| 35 | + uses: docker/metadata-action@v5.7.0 |
| 36 | + with: |
| 37 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 38 | + |
| 39 | + - name: Build and push |
| 40 | + if: steps.filter.outputs.docker-rebuild == 'true' |
| 41 | + uses: docker/build-push-action@v6 |
| 42 | + with: |
| 43 | + context: "." |
| 44 | + push: true |
| 45 | + tags: ${{ steps.meta.outputs.tags }} |
| 46 | + labels: ${{ steps.meta.outputs.labels }} |
| 47 | + |
| 48 | + build: |
| 49 | + runs-on: ubuntu-latest |
| 50 | + needs: docker-rebuild |
| 51 | + steps: |
| 52 | + - uses: actions/checkout@v2 |
| 53 | + with: |
| 54 | + fetch-depth: 0 |
| 55 | + |
| 56 | + - name: Check if this branch has its own docker image |
| 57 | + id: check_image |
| 58 | + run: |- |
| 59 | + IMAGE_NAME="${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}" |
| 60 | + if docker pull $IMAGE_NAME; then |
| 61 | + echo "Image exists" |
| 62 | + echo "ref=${{ github.ref_name }}" >> $GITHUB_OUTPUT |
| 63 | + else |
| 64 | + echo "Image does not exist" |
| 65 | + echo "ref=main" >> $GITHUB_OUTPUT |
| 66 | + fi |
| 67 | +
|
| 68 | + - name: Build |
| 69 | + run: | |
| 70 | + docker run --rm -v $(pwd):/src -w /src ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.check_image.outputs.ref }} just build |
| 71 | +
|
| 72 | + - name: Upload artifact |
| 73 | + uses: actions/upload-pages-artifact@v3 |
| 74 | + with: |
| 75 | + path: build/ |
| 76 | + |
| 77 | + deploy: |
| 78 | + needs: build |
| 79 | + if: github.ref_name == github.event.repository.default_branch |
| 80 | + environment: |
| 81 | + name: github-pages |
| 82 | + url: ${{ steps.deployment.outputs.page_url }} |
| 83 | + concurrency: |
| 84 | + group: "pages" |
| 85 | + cancel-in-progress: false |
| 86 | + permissions: |
| 87 | + contents: read |
| 88 | + pages: write |
| 89 | + id-token: write |
| 90 | + runs-on: ubuntu-latest |
| 91 | + steps: |
| 92 | + - name: Deploy to GitHub Pages |
| 93 | + id: deployment |
| 94 | + uses: actions/deploy-pages@v4 |
0 commit comments