From 48b62d8835e277847ac8576846a45f1d42a5f7cf Mon Sep 17 00:00:00 2001 From: Sijie Date: Thu, 5 Sep 2024 10:06:19 -0700 Subject: [PATCH] update package build scripts --- .github/workflows/docker-publish.yml | 57 ++++++++++++++++++++++++++++ .github/workflows/manual-build.yml | 11 ------ .github/workflows/pr_build.yml | 43 --------------------- .github/workflows/release-main.yml | 25 ------------ 4 files changed, 57 insertions(+), 79 deletions(-) create mode 100644 .github/workflows/docker-publish.yml delete mode 100644 .github/workflows/manual-build.yml delete mode 100644 .github/workflows/pr_build.yml delete mode 100644 .github/workflows/release-main.yml diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..83e1f1c --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,57 @@ +name: Docker + +on: + workflow_dispatch: + push: + branches: [ "main", "master", "develop" ] + # Publish semver tags as releases. + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' + - '[0-9]+.[0-9]+.[0-9]+' + - '[0-9]+.[0-9]+.[0-9]+-*' + pull_request: + branches: [ "main", "master", "develop" ] + release: + types: [published] + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/manual-build.yml b/.github/workflows/manual-build.yml deleted file mode 100644 index 944f903..0000000 --- a/.github/workflows/manual-build.yml +++ /dev/null @@ -1,11 +0,0 @@ ---- -name: Manual Build & Push -on: - workflow_dispatch: -jobs: - build-push: - uses: kbase/.github/.github/workflows/reusable_build-push.yml@main - with: - name: '${{ github.event.repository.name }}-develop' - tags: br-${{ github.ref_name }} - secrets: inherit diff --git a/.github/workflows/pr_build.yml b/.github/workflows/pr_build.yml deleted file mode 100644 index 0fa1c46..0000000 --- a/.github/workflows/pr_build.yml +++ /dev/null @@ -1,43 +0,0 @@ ---- -name: Pull Request Build, Tag, & Push -on: - pull_request: - branches: - - develop - - main - - master - types: - - opened - - reopened - - synchronize - - closed -jobs: - build-develop-open: - if: github.base_ref == 'develop' && github.event.pull_request.merged == false - uses: kbase/.github/.github/workflows/reusable_build.yml@main - secrets: inherit - build-develop-merge: - if: github.base_ref == 'develop' && github.event.pull_request.merged == true - uses: kbase/.github/.github/workflows/reusable_build-push.yml@main - with: - name: '${{ github.event.repository.name }}-develop' - tags: pr-${{ github.event.number }},latest - secrets: inherit - build-main-open: - if: (github.base_ref == 'main' || github.base_ref == 'master') && github.event.pull_request.merged == false - uses: kbase/.github/.github/workflows/reusable_build-push.yml@main - with: - name: '${{ github.event.repository.name }}' - tags: pr-${{ github.event.number }} - secrets: inherit - build-main-merge: - if: (github.base_ref == 'main' || github.base_ref == 'master') && github.event.pull_request.merged == true - uses: kbase/.github/.github/workflows/reusable_build-push.yml@main - with: - name: '${{ github.event.repository.name }}' - tags: pr-${{ github.event.number }},latest-rc - secrets: inherit - trivy-scans: - if: (github.base_ref == 'develop' || github.base_ref == 'main' || github.base_ref == 'master' ) && github.event.pull_request.merged == false - uses: kbase/.github/.github/workflows/reusable_trivy-scans.yml@main - secrets: inherit diff --git a/.github/workflows/release-main.yml b/.github/workflows/release-main.yml deleted file mode 100644 index a254678..0000000 --- a/.github/workflows/release-main.yml +++ /dev/null @@ -1,25 +0,0 @@ ---- -name: Release - Build & Push Image -on: - release: - branches: - - main - - master - types: [ published ] -jobs: - check-source-branch: - uses: kbase/.github/.github/workflows/reusable_validate-branch.yml@main - with: - build_branch: '${{ github.event.release.target_commitish }}' - validate-release-tag: - needs: check-source-branch - uses: kbase/.github/.github/workflows/reusable_validate-release-tag.yml@main - with: - release_tag: '${{ github.event.release.tag_name }}' - build-push: - needs: validate-release-tag - uses: kbase/.github/.github/workflows/reusable_build-push.yml@main - with: - name: '${{ github.event.repository.name }}' - tags: '${{ github.event.release.tag_name }},latest' - secrets: inherit