Merge pull request #11 from alauda/fix/AIT-45673 #39
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: ci | |
on: | |
push: | |
branches: | |
- 'main' | |
- 'dev' | |
pull_request: | |
branches: [ "main" ] | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v3 | |
- name: Get registry tags | |
shell: bash | |
run: | | |
GIT_BRANCH="${GITHUB_REF_NAME}" | |
if [ "${GITHUB_REF}" == "refs/pull/"*"/merge" ]; then | |
GIT_BRANCH="pr-$(echo ${GITHUB_REF} | sed 's|refs/pull/(.*)/merge|\1|g')-${GITHUB_SHA:0:8}" | |
fi | |
if [ "${GITHUB_REF}" == "refs/remotes/pull/"*"/merge" ]; then | |
GIT_BRANCH="pr-$(echo ${GITHUB_REF} | sed 's|refs/remotes/pull/(.*)/merge|\1|g')-${GITHUB_SHA:0:8}" | |
fi | |
GIT_BRANCH=$(echo "${GIT_BRANCH}" | tr '/' '-') | |
echo "GIT_BRANCH=${GIT_BRANCH}" >> $GITHUB_ENV | |
REGISTRY_TAGS="${REGISTRY}/${IMAGE_NAME}:${GIT_BRANCH}" | |
if [ "${GIT_BRANCH}" == "main" ]; then | |
REGISTRY_TAGS="${REGISTRY_TAGS},${REGISTRY}/${IMAGE_NAME}:latest" | |
fi | |
echo "REGISTRY_TAGS=${REGISTRY_TAGS}" >> $GITHUB_ENV | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push | |
uses: docker/build-push-action@v3 | |
with: | |
context: . | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
tags: ${{ env.REGISTRY_TAGS }} |