|
| 1 | +name: Workflow used by docker-image workflows |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + outputs: |
| 6 | + REGISTRY: |
| 7 | + description: "Container registry" |
| 8 | + value: ${{ jobs.build-image-and-test-docs.outputs.REGISTRY }} |
| 9 | + IMAGE_NAME: |
| 10 | + description: "Docker image name" |
| 11 | + value: ${{ jobs.build-image-and-test-docs.outputs.IMAGE_NAME }} |
| 12 | + version_tag: |
| 13 | + description: "Version tag from Dockerfile" |
| 14 | + value: ${{ jobs.check-version.outputs.VERSION_TAG }} |
| 15 | + |
| 16 | +# Defines custom environment variables for the workflow. |
| 17 | +env: |
| 18 | + REGISTRY: ghcr.io |
| 19 | + IMAGE_BASENAME: ctsm-docs |
| 20 | + REPO: ${{ github.repository }} |
| 21 | + |
| 22 | +# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. |
| 23 | +jobs: |
| 24 | + build-image-and-test-docs: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + # Variables that might be needed by the calling workflow |
| 27 | + outputs: |
| 28 | + REGISTRY: ${{ env.REGISTRY }} |
| 29 | + IMAGE_NAME: ${{ steps.set-image-name.outputs.IMAGE_NAME }} |
| 30 | + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. |
| 31 | + permissions: |
| 32 | + contents: read |
| 33 | + |
| 34 | + steps: |
| 35 | + |
| 36 | + - name: Checkout repository |
| 37 | + uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
| 38 | + |
| 39 | + # Ensure that the repository part of IMAGE_NAME is lowercase. This is needed because Docker requires image names to be entirely lowercase. Note that the *image name* part, set as IMAGE_BASENAME in the env block above, is *not* converted. This will cause the check-version job to fail if the IMAGE_BASENAME contains capitals. We don't want to silently fix that here; rather, we require the user to specify a lowercase IMAGE_BASENAME. |
| 40 | + - name: Get image name with lowercase repo |
| 41 | + id: set-image-name |
| 42 | + run: | |
| 43 | + lowercase_repo=$(echo $REPO | tr '[:upper:]' '[:lower:]') |
| 44 | + echo "IMAGE_NAME=${lowercase_repo}/${IMAGE_BASENAME}" >> $GITHUB_ENV |
| 45 | + echo "IMAGE_NAME=${lowercase_repo}/${IMAGE_BASENAME}" >> $GITHUB_OUTPUT |
| 46 | +
|
| 47 | + # Uses the `docker/login-action` action to log in to the Container registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. |
| 48 | + - name: Log in to the Container registry |
| 49 | + uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 |
| 50 | + with: |
| 51 | + registry: ${{ env.REGISTRY }} |
| 52 | + username: ${{ github.actor }} |
| 53 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 54 | + |
| 55 | + # 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. |
| 56 | + - name: Extract metadata (tags, labels) for Docker |
| 57 | + id: meta |
| 58 | + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 |
| 59 | + with: |
| 60 | + images: ${{ env.REGISTRY }}/${{ steps.set-image-name.outputs.IMAGE_NAME }} |
| 61 | + |
| 62 | + # This step uses the `docker/build-push-action` action to build the image, based on the ctsm-docs `Dockerfile`. |
| 63 | + # 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. |
| 64 | + # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. |
| 65 | + # v6.15.0 |
| 66 | + - name: Build Docker image |
| 67 | + id: build-image |
| 68 | + uses: docker/build-push-action@471d1dc4e07e5cdedd4c2171150001c434f0b7a4 |
| 69 | + with: |
| 70 | + context: doc/ctsm-docs_container |
| 71 | + push: false |
| 72 | + load: true |
| 73 | + tags: ${{ steps.meta.outputs.tags }} |
| 74 | + labels: ${{ steps.meta.outputs.labels }} |
| 75 | + |
| 76 | + # Check out all submodules because we might :literalinclude: something from one |
| 77 | + - name: Checkout all submodules |
| 78 | + run: | |
| 79 | + bin/git-fleximod update -o |
| 80 | +
|
| 81 | + - name: Set image tag for docs build |
| 82 | + id: set-image-tag |
| 83 | + run: | |
| 84 | + echo "IMAGE_TAG=$(echo '${{ steps.meta.outputs.tags }}' | head -n 1 | cut -d',' -f1)" >> $GITHUB_ENV |
| 85 | +
|
| 86 | + - name: Build docs using Docker (Podman has trouble on GitHub runners) |
| 87 | + id: build-docs |
| 88 | + run: | |
| 89 | + cd doc && ./build_docs -b ${PWD}/_build -c -d -i $IMAGE_TAG |
| 90 | +
|
| 91 | +
|
| 92 | + check-version: |
| 93 | + needs: build-image-and-test-docs |
| 94 | + uses: ./.github/workflows/docker-image-get-version.yml |
| 95 | + with: |
| 96 | + registry: ${{ needs.build-image-and-test-docs.outputs.REGISTRY }} |
| 97 | + image_name: ${{ needs.build-image-and-test-docs.outputs.IMAGE_NAME }} |
0 commit comments