|
| 1 | +name: GHCR |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - v* |
| 7 | + |
| 8 | +# 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. |
| 9 | +env: |
| 10 | + REGISTRY: ghcr.io |
| 11 | + IMAGE_NAME: ${{ github.repository }} |
| 12 | + |
| 13 | +# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. |
| 14 | +jobs: |
| 15 | + # Run tests. |
| 16 | + # See also https://docs.docker.com/docker-hub/builds/automated-testing/ |
| 17 | + test: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v3 |
| 22 | + |
| 23 | + - name: Use Node.js |
| 24 | + uses: actions/setup-node@v3 |
| 25 | + with: |
| 26 | + node-version: '18.16.0' |
| 27 | + |
| 28 | + - name: Install dependencies |
| 29 | + run: yarn --frozen-lockfile |
| 30 | + |
| 31 | + - name: Linting |
| 32 | + run: yarn lint |
| 33 | + |
| 34 | + - name: Build |
| 35 | + run: yarn build |
| 36 | + |
| 37 | + build-and-push-image: |
| 38 | + needs: test |
| 39 | + runs-on: ubuntu-latest |
| 40 | + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. |
| 41 | + permissions: |
| 42 | + contents: read |
| 43 | + packages: write |
| 44 | + # |
| 45 | + steps: |
| 46 | + - name: Checkout repository |
| 47 | + uses: actions/checkout@v4 |
| 48 | + # 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. |
| 49 | + - name: Log in to the Container registry |
| 50 | + uses: docker/login-action@v3 |
| 51 | + with: |
| 52 | + registry: ${{ env.REGISTRY }} |
| 53 | + username: ${{ github.actor }} |
| 54 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 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@v5 |
| 59 | + with: |
| 60 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 61 | + # 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. |
| 62 | + # 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. |
| 63 | + # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. |
| 64 | + - name: Build and push Docker image |
| 65 | + uses: docker/build-push-action@v5 |
| 66 | + with: |
| 67 | + context: . |
| 68 | + push: true |
| 69 | + tags: ${{ steps.meta.outputs.tags }} |
| 70 | + labels: ${{ steps.meta.outputs.labels }} |
0 commit comments