From 979b4991fa805b833492cdb7475d2de328669ccf Mon Sep 17 00:00:00 2001 From: Yuxing Deng Date: Wed, 17 Jul 2024 16:59:44 +0800 Subject: [PATCH] feat: switch to GHA --- .drone.yml => .drone_backup.yml | 0 .github/workflows/pr.yaml | 18 +++++++++ .github/workflows/push.yaml | 70 +++++++++++++++++++++++++++++++++ scripts/github_ci | 9 +++++ 4 files changed, 97 insertions(+) rename .drone.yml => .drone_backup.yml (100%) create mode 100644 .github/workflows/pr.yaml create mode 100644 .github/workflows/push.yaml create mode 100755 scripts/github_ci diff --git a/.drone.yml b/.drone_backup.yml similarity index 100% rename from .drone.yml rename to .drone_backup.yml diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml new file mode 100644 index 0000000..e11854a --- /dev/null +++ b/.github/workflows/pr.yaml @@ -0,0 +1,18 @@ +name: pull request +on: + pull_request: + types: + - opened + - reopened + - synchronize +jobs: + pr-build: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v4 + - + name: Build to test + run: make ci + diff --git a/.github/workflows/push.yaml b/.github/workflows/push.yaml new file mode 100644 index 0000000..e505d3e --- /dev/null +++ b/.github/workflows/push.yaml @@ -0,0 +1,70 @@ +name: Push to Master + +on: + push: + branches: + - main + tags: + - 'v*.*.*' # Matches any tag that starts with 'v' and follows semantic versioning + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Login to Aliyun ACR + uses: docker/login-action@v3 + with: + registry: registry.cn-shenzhen.aliyuncs.com + username: ${{ secrets.ACR_USERNAME }} + password: ${{ secrets.ACR_TOKEN }} + if: ${{ env.ALIYUN == 'true' }} + - name: Login to Dockerhub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: CI + if: startsWith(github.ref, 'refs/heads/') + env: + CROSS: push + run: make github_ci + + - name: CI + if: startsWith(github.ref, 'refs/tags/') + env: + CROSS: tag + run: make github_ci + + - name: Prepare for packaging image + run: cp dist/* package/ + - name: Set docker iamge name + id: image-name + env: + REPO_OVERRIDE: ${{ vars.REPO || 'cnrancher' }} + IMAGE_OVERRIDE: ${{ vars.IMAGE || 'kube-explorer' }} + run: | + tag_name=latest; + if [[ ${GITHUB_REF} == refs/tags/* ]]; then tag_name=${GITHUB_REF#refs/tags/}; fi; + echo "image_name=${REPO_OVERRIDE}/${IMAGE_OVERRIDE}:${tag_name}" >> $GITHUB_OUTPUT; + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build to Dockerhub + uses: docker/build-push-action@v6 + with: + platforms: linux/amd64,linux/arm64/v8 + tags: "${{ steps.image-name.outputs.image_name }}" + context: package + push: true + - name: Build to Aliyun + uses: docker/build-push-action@v6 + with: + tags: registry.cn-shenzhen.aliyuncs.com/${{ steps.image-name.outputs.image_name }} + context: package + push: true + if: ${{ env.ALIYUN == 'true' }} diff --git a/scripts/github_ci b/scripts/github_ci new file mode 100755 index 0000000..ab93aa5 --- /dev/null +++ b/scripts/github_ci @@ -0,0 +1,9 @@ +#!/bin/bash +set -e + +cd $(dirname $0) + +./download +./validate +./build +