-
Notifications
You must be signed in to change notification settings - Fork 0
55 lines (47 loc) · 1.88 KB
/
docker-build.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
name: Build and Push Docker Image
on:
push:
branches:
- main
pull_request:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
# Step 1: Checkout the repository code
- name: Checkout repository
uses: actions/checkout@v3
# Step 2: Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# Step 3: Fetch the latest release version from GitHub API
- name: Get latest release version
id: get_version
run: |
VERSION=$(curl -s https://api.github.com/repos/Byte-Nova/Rimworld-Together/releases/latest | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
if [ -z "$VERSION" ]; then
echo "Failed to fetch version from GitHub."
exit 1
fi
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Latest version is $VERSION."
# Step 4: Log in to GitHub Container Registry (GHCR)
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Step 5: Build the Docker image with both the version and latest tags (lowercase repository)
- name: Build Docker image
run: |
LOWERCASE_REPO=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
docker build --build-arg VERSION=$VERSION -t ghcr.io/$LOWERCASE_REPO:$VERSION .
docker tag ghcr.io/$LOWERCASE_REPO:$VERSION ghcr.io/$LOWERCASE_REPO:latest
# Step 6: Push the Docker image to GHCR (both version and latest tags)
- name: Push Docker image
run: |
LOWERCASE_REPO=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
docker push ghcr.io/$LOWERCASE_REPO:$VERSION
docker push ghcr.io/$LOWERCASE_REPO:latest