-
-
Notifications
You must be signed in to change notification settings - Fork 968
ci: build test image on master pushes #3120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 10 commits
a25b63b
6cf1690
bf35e17
765ce94
97efdc2
053d6a7
04428b3
540b22b
440479f
1d3422c
14217af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,19 +2,92 @@ name: Docker Image CI/CD | |
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - master | ||
| tags: | ||
| - 'v*' | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| publish-docker: | ||
| build-test-image: | ||
| if: github.event_name == 'push' && startsWith(github.ref, 'refs/heads/master') | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} | ||
| GHCR_OWNER: ${{ github.repository_owner }} | ||
| HAS_GHCR_TOKEN: ${{ secrets.GHCR_GITHUB_TOKEN != '' }} | ||
|
|
||
| steps: | ||
| - name: Pull The Codes | ||
| - name: Checkout | ||
| uses: actions/checkout@v5 | ||
| with: | ||
| fetch-depth: 0 # Must be 0 so we can fetch tags | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Build Dashboard | ||
| run: | | ||
| cd dashboard | ||
| npm install | ||
| npm run build | ||
| mkdir -p dist/assets | ||
| echo $(git rev-parse HEAD) > dist/assets/version | ||
| cd .. | ||
| mkdir -p data | ||
| cp -r dashboard/dist data/ | ||
|
|
||
| - name: Determine test image tags | ||
| id: test-meta | ||
| run: | | ||
| short_sha=$(echo "${GITHUB_SHA}" | cut -c1-12) | ||
| echo "short_sha=$short_sha" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Set QEMU | ||
| uses: docker/setup-qemu-action@v3 | ||
|
|
||
| - name: Set Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Log in to DockerHub | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| username: ${{ secrets.DOCKER_HUB_USERNAME }} | ||
| password: ${{ secrets.DOCKER_HUB_PASSWORD }} | ||
|
|
||
| - name: Login to GitHub Container Registry | ||
| if: env.HAS_GHCR_TOKEN == 'true' | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ env.GHCR_OWNER }} | ||
| password: ${{ secrets.GHCR_GITHUB_TOKEN }} | ||
|
|
||
| - name: Build and Push Test Image | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: . | ||
| platforms: linux/amd64,linux/arm64 | ||
| push: true | ||
| tags: | | ||
| ${{ format('{0}/astrbot:test-latest', env.DOCKER_HUB_USERNAME) }} | ||
| ${{ format('{0}/astrbot:test-{1}', env.DOCKER_HUB_USERNAME, steps.test-meta.outputs.short_sha) }} | ||
| ${{ env.HAS_GHCR_TOKEN == 'true' && format('ghcr.io/{0}/astrbot:test-latest', env.GHCR_OWNER) || '' }} | ||
| ${{ env.HAS_GHCR_TOKEN == 'true' && format('ghcr.io/{0}/astrbot:test-{1}', env.GHCR_OWNER, steps.test-meta.outputs.short_sha) || '' }} | ||
|
|
||
| - name: Post build notifications | ||
| run: echo "Test Docker image has been built and pushed successfully" | ||
|
|
||
| build-release-image: | ||
| if: github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')) | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }} | ||
| GHCR_OWNER: ${{ github.repository_owner }} | ||
| HAS_GHCR_TOKEN: ${{ secrets.GHCR_GITHUB_TOKEN != '' }} | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v5 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Get latest tag (only on manual trigger) | ||
| id: get-latest-tag | ||
|
|
@@ -27,21 +100,22 @@ jobs: | |
| if: github.event_name == 'workflow_dispatch' | ||
| run: git checkout ${{ steps.get-latest-tag.outputs.latest_tag }} | ||
|
|
||
| - name: Check if version is pre-release | ||
| id: check-prerelease | ||
| - name: Compute release metadata | ||
| id: release-meta | ||
| run: | | ||
| if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | ||
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | ||
| version="${{ steps.get-latest-tag.outputs.latest_tag }}" | ||
| else | ||
| version="${{ github.ref_name }}" | ||
| version="${GITHUB_REF#refs/tags/}" | ||
| fi | ||
| if [[ "$version" == *"beta"* ]] || [[ "$version" == *"alpha"* ]]; then | ||
| echo "is_prerelease=true" >> $GITHUB_OUTPUT | ||
| echo "Version $version is a pre-release, will not push latest tag" | ||
| echo "Version $version marked as pre-release" | ||
| else | ||
| echo "is_prerelease=false" >> $GITHUB_OUTPUT | ||
| echo "Version $version is a stable release, will push latest tag" | ||
| echo "Version $version marked as stable" | ||
| fi | ||
| echo "version=$version" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Build Dashboard | ||
| run: | | ||
|
|
@@ -67,23 +141,24 @@ jobs: | |
| password: ${{ secrets.DOCKER_HUB_PASSWORD }} | ||
|
|
||
| - name: Login to GitHub Container Registry | ||
| if: env.HAS_GHCR_TOKEN == 'true' | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| registry: ghcr.io | ||
| username: Soulter | ||
| username: ${{ env.GHCR_OWNER }} | ||
| password: ${{ secrets.GHCR_GITHUB_TOKEN }} | ||
|
|
||
| - name: Build and Push Docker to DockerHub and Github GHCR | ||
| - name: Build and Push Release Image | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: . | ||
| platforms: linux/amd64,linux/arm64 | ||
| push: true | ||
| tags: | | ||
| ${{ steps.check-prerelease.outputs.is_prerelease == 'false' && format('{0}/astrbot:latest', secrets.DOCKER_HUB_USERNAME) || '' }} | ||
| ${{ secrets.DOCKER_HUB_USERNAME }}/astrbot:${{ github.event_name == 'workflow_dispatch' && steps.get-latest-tag.outputs.latest_tag || github.ref_name }} | ||
| ${{ steps.check-prerelease.outputs.is_prerelease == 'false' && 'ghcr.io/soulter/astrbot:latest' || '' }} | ||
| ghcr.io/soulter/astrbot:${{ github.event_name == 'workflow_dispatch' && steps.get-latest-tag.outputs.latest_tag || github.ref_name }} | ||
| ${{ steps.release-meta.outputs.is_prerelease == 'false' && format('{0}/astrbot:latest', env.DOCKER_HUB_USERNAME) || '' }} | ||
| ${{ steps.release-meta.outputs.is_prerelease == 'false' && env.HAS_GHCR_TOKEN == 'true' && format('ghcr.io/{0}/astrbot:latest', env.GHCR_OWNER) || '' }} | ||
| ${{ format('{0}/astrbot:{1}', env.DOCKER_HUB_USERNAME, steps.release-meta.outputs.version) }} | ||
| ${{ env.HAS_GHCR_TOKEN == 'true' && format('ghcr.io/{0}/astrbot:{1}', env.GHCR_OWNER, steps.release-meta.outputs.version) || '' }} | ||
|
Comment on lines
+169
to
+171
|
||
|
|
||
| - name: Post build notifications | ||
| run: echo "Docker image has been built and pushed successfully" | ||
| run: echo "Release Docker image has been built and pushed successfully" | ||
Uh oh!
There was an error while loading. Please reload this page.