Blame Raw
Cohee · b06a6295 · · 94 lines (3.6 KB)
1 contributor
1# This workflow will publish a docker image for every full release to the GitHub package repository
2
3name: Create Docker Image (Release and Staging)
4
5on:
6 release:
7 # Allow pre-releases
8 types: [published]
9 schedule:
10 # Build the staging image everyday at 00:00 UTC
11 - cron: "0 0 * * *"
12 push:
13 # Temporary workaround
14 branches:
15 - release
16
17env:
18 # This should allow creation of docker images even in forked repositories
19 REPO: ${{ github.repository }}
20 REGISTRY: ghcr.io
21
22jobs:
23 build:
24 if: github.repository == 'SillyTavern/SillyTavern'
25 runs-on: ubuntu-latest
26
27 steps:
28 # Workaround for GitHub repo names containing uppercase characters
29 - name: Set lowercase repo name
30 run: |
31 echo "IMAGE_NAME=${REPO,,}" >> ${GITHUB_ENV}
32
33 # Using the following workaround because currently GitHub Actions
34 # does not support logical AND/OR operations on triggers
35 # It's currently not possible to have `branches` under the `schedule` trigger
36 - name: Checkout the release branch (on release)
37 if: ${{ github.event_name == 'release' || github.event_name == 'push' }}
38 uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
39 with:
40 ref: "release"
41
42 - name: Checkout the staging branch
43 if: ${{ github.event_name == 'schedule' }}
44 uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633 # v4.1.2
45 with:
46 ref: "staging"
47
48 # Get current branch name
49 # This is also part of the workaround for Actions not allowing logical
50 # AND/OR operators on triggers
51 # Otherwise the action triggered by schedule always has ref_name = release
52 - name: Get the current branch name
53 run: |
54 echo "BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)" >> ${GITHUB_ENV}
55
56 # Setting up QEMU for multi-arch image build
57 - name: Set up QEMU
58 uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3
59
60 - name: Set up Docker Buildx
61 uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3
62
63 - name: Extract metadata (tags, labels) for the image
64 uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # v5.5.1
65 id: metadata
66 with:
67 images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
68 # Release version tag if the workflow is triggered by a release
69 # Branch name tag if the workflow is triggered by a push
70 # Latest tag if the branch is release and the workflow is triggered by a push
71 tags: |
72 ${{ github.event_name == 'release' && github.ref_name || env.BRANCH_NAME }}
73 ${{ github.event_name == 'push' && env.BRANCH_NAME == 'release' && 'latest' || '' }}
74
75 # Login into package repository as the person who created the release
76 - name: Log in to the Container registry
77 uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3
78 with:
79 registry: ${{ env.REGISTRY }}
80 username: ${{ github.actor }}
81 password: ${{ secrets.GITHUB_TOKEN }}
82
83 # Build docker image using dockerfile for amd64 and arm64
84 # Tag it with branch name
85 # Assumes branch name is the version number
86 - name: Build and push
87 uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # v5.3.0
88 with:
89 context: .
90 platforms: linux/amd64,linux/arm64
91 file: Dockerfile
92 push: true
93 tags: ${{ steps.metadata.outputs.tags }}
94 labels: ${{ steps.metadata.outputs.labels }}