Skip to content

Commit daf7b3a

Browse files
authored
Merge pull request #6 from Lego-Fan9/Actions-for-1.1.0
Add GitHub actions for v1.1.0
2 parents a5a555b + c5b04a5 commit daf7b3a

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Docker
2+
3+
on:
4+
push:
5+
branches: [ "**" ]
6+
tags: [ 'v*.*.*' ]
7+
pull_request:
8+
branches: [ "**" ]
9+
schedule:
10+
- cron: '0 3 * * 1,3,5'
11+
12+
env:
13+
REGISTRY: ghcr.io
14+
IMAGE_NAME: ${{ github.repository }}
15+
16+
jobs:
17+
build:
18+
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
packages: write
23+
id-token: write
24+
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
28+
29+
# Set IMAGE_NAME to lowercase
30+
- name: Set image name to lowercase
31+
run: |
32+
IMAGE_NAME=$(echo "${GITHUB_REPOSITORY}" | tr '[:upper:]' '[:lower:]')
33+
echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV
34+
35+
36+
# Set up Docker BuildKit
37+
- name: Set up Docker Buildx
38+
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
39+
40+
# Log into the registry
41+
- name: Log into registry ${{ env.REGISTRY }}
42+
if: github.event_name != 'pull_request'
43+
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
44+
with:
45+
registry: ${{ env.REGISTRY }}
46+
username: ${{ github.actor }}
47+
password: ${{ secrets.GITHUB_TOKEN }}
48+
49+
# Extract Docker metadata
50+
- name: Extract Docker metadata
51+
id: meta
52+
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
53+
with:
54+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
55+
56+
57+
# Set Docker tags for non-main branches
58+
- name: Set Docker tags
59+
id: set-tags
60+
run: |
61+
if [[ "${GITHUB_REF##*/}" == "main" ]]; then
62+
echo "tags=${{ steps.meta.outputs.tags }}" >> $GITHUB_OUTPUT
63+
else
64+
BRANCH=$(echo "${GITHUB_REF##*/}" | tr '/' '-' | tr -cd '[:alnum:]-')
65+
echo "tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${BRANCH}" >> $GITHUB_OUTPUT
66+
fi
67+
68+
# Build and push Docker image (multi-platform)
69+
- name: Build and push Docker image
70+
id: build-and-push
71+
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
72+
with:
73+
context: .
74+
file: ./discord-avatar-hash-container/Dockerfile
75+
push: ${{ github.event_name != 'pull_request' }}
76+
tags: ${{ steps.set-tags.outputs.tags }}
77+
labels: ${{ steps.meta.outputs.labels }}
78+
platforms: linux/arm64
79+
cache-from: type=gha
80+
cache-to: type=gha,mode=max

0 commit comments

Comments
 (0)