Skip to content

ci: update github-script #1

ci: update github-script

ci: update github-script #1

name: Build and Publish Docker Image
on:
push:
branches:
- '**'
tags:
- "v*"
jobs:
# define job to build and publish docker image
build-and-push-docker-image:
strategy:
matrix:
app: [admin-server, api-server, auth-server, image-server]
include:
- app: api-server
build-target: release-with-packages
name: '[${{ matrix.app }}] Build & push image'
runs-on: ubuntu-latest
outputs:
image_tag: ${{ steps.image_output.outputs.image_tag }}
env:
IMAGE: '${{ github.repository_owner }}/${{ matrix.app }}'
APP: ${{ matrix.app }}
BUILD_TARGET: release
steps:
- name: Checkout code
uses: actions/checkout@v3
- if: ${{ matrix.build-target }}
name: Set correct build target
run: echo "BUILD_TARGET=${{ matrix.build-target}}" >> $GITHUB_ENV
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.IMAGE }}
tags: |
# branch event
type=ref,event=branch,suffix=-{{sha}}
# tag event
type=ref,event=tag
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build image and push to GitHub Container Registry
id: docker_build
uses: docker/build-push-action@v3
with:
context: .
push: true
tags: 'ghcr.io/${{ steps.meta.outputs.tags }}'
build-args: |
APP=${{ matrix.app }}
- name: Adding image to step summary
run: |
echo "new image: \`ghcr.io/${{ github.repository_owner}}/${{ matrix.app }}:${{ steps.meta.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
- name: Add image output
id: image_output
run: echo "image_tag=${{ steps.meta.outputs.version }}" >> "$GITHUB_OUTPUT"
add_images_to_commit_comment:
name: Add images to commit comment
runs-on: ubuntu-latest
needs: build-and-push-docker-image
steps:
- uses: actions/github-script@v7
env:
STDOUT: "New images: \n
`ghcr.io/${{ github.repository_owner }}/admin-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}`\n
`ghcr.io/${{ github.repository_owner }}/api-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}`\n
`ghcr.io/${{ github.repository_owner }}/auth-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}`\n
`ghcr.io/${{ github.repository_owner }}/image-server:${{ needs.build-and-push-docker-image.outputs.image_tag }}`
"
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.repos.createCommitComment({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: context.sha,
body: process.env.STDOUT
})