|
| 1 | +name: ☁️ Build Container |
| 2 | + |
| 3 | +# Configures this workflow to run every time a change is pushed to the branch called `release`. |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: ["main"] |
| 7 | + release: |
| 8 | + types: [published] |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +concurrency: |
| 12 | + group: container-build |
| 13 | + cancel-in-progress: true |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: read |
| 17 | + packages: write |
| 18 | + |
| 19 | +# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. |
| 20 | +env: |
| 21 | + REGISTRY: ghcr.io |
| 22 | + IMAGE_NAME: ${{ github.repository }} |
| 23 | + |
| 24 | +# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. |
| 25 | +jobs: |
| 26 | + submodule: |
| 27 | + strategy: |
| 28 | + matrix: |
| 29 | + repo: [mkdocs-material-insiders, brand] |
| 30 | + uses: privacyguides/.github/.github/workflows/download-repo.yml@main |
| 31 | + with: |
| 32 | + repo: ${{ matrix.repo }} |
| 33 | + secrets: |
| 34 | + ACTIONS_SSH_KEY: ${{ secrets.ACTIONS_SSH_KEY }} |
| 35 | + |
| 36 | + build-and-push-image: |
| 37 | + needs: submodule |
| 38 | + runs-on: ubuntu-latest |
| 39 | + steps: |
| 40 | + - name: Checkout repository |
| 41 | + uses: actions/checkout@v4 |
| 42 | + with: |
| 43 | + fetch-depth: 0 |
| 44 | + |
| 45 | + - uses: actions/download-artifact@v4 |
| 46 | + with: |
| 47 | + pattern: repo-* |
| 48 | + path: modules |
| 49 | + |
| 50 | + - run: | |
| 51 | + rm -rf modules/mkdocs-material |
| 52 | + mv modules/repo-mkdocs-material-insiders modules/mkdocs-material |
| 53 | + rm -rf theme/assets/brand |
| 54 | + mv modules/repo-brand theme/assets/brand |
| 55 | +
|
| 56 | + # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. |
| 57 | + - name: Log in to the Container registry |
| 58 | + |
| 59 | + with: |
| 60 | + registry: ${{ env.REGISTRY }} |
| 61 | + username: ${{ github.actor }} |
| 62 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 63 | + |
| 64 | + # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. |
| 65 | + - name: Extract metadata (tags, labels) for Docker |
| 66 | + id: meta |
| 67 | + |
| 68 | + with: |
| 69 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 70 | + tags: | |
| 71 | + type=ref,event=branch |
| 72 | + type=ref,event=tag |
| 73 | + type=ref,event=pr |
| 74 | + type=sha |
| 75 | + flavor: | |
| 76 | + latest=${{ github.event_name == 'release' }} |
| 77 | +
|
| 78 | + # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. |
| 79 | + # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. |
| 80 | + # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. |
| 81 | + - name: Build and push Docker image |
| 82 | + |
| 83 | + with: |
| 84 | + context: . |
| 85 | + push: true |
| 86 | + tags: ${{ steps.meta.outputs.tags }} |
| 87 | + labels: ${{ steps.meta.outputs.labels }} |
| 88 | + |
| 89 | + cleanup: |
| 90 | + if: ${{ always() }} |
| 91 | + needs: build-and-push-image |
| 92 | + uses: privacyguides/.github/.github/workflows/cleanup.yml@main |
0 commit comments