-
Notifications
You must be signed in to change notification settings - Fork 0
129 lines (105 loc) · 4.43 KB
/
Copy pathdocker-image.yml
File metadata and controls
129 lines (105 loc) · 4.43 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: Docker Image CI
on:
push:
branches: ["main"]
pull_request:
branches: ["main"]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: "refs/heads/main" # Replace 'main' with your default branch name
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9
run_install: false
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "22"
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- uses: actions/cache@v4
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
env:
HUSKY: 0
run: |
pnpm install
- name: Build the app
run: |
pnpx nx build sinlessgames-ui --output-path=dist/apps/sinlessgames-ui
- name: Log in to Docker Hub
run: echo "${{ secrets.DOCKER_HUB_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_HUB_USERNAME }}" --password-stdin
- name: Determine previous version
id: determine-previous-version
run: |
PREVIOUS_VERSION=$(curl -s "https://registry.hub.docker.com/v2/repositories/sinless777/sinlessgames-ui/tags" | jq -r '.results[].name' | grep -v 'latest' | sort -V | tail -n 1)
echo "Previous version: $PREVIOUS_VERSION"
echo "PREVIOUS_VERSION=$PREVIOUS_VERSION" >> $GITHUB_ENV
- name: Determine new version
id: determine-new-version
run: |
# Extract version from package.json
PACKAGE_VERSION=$(jq -r '.version' package.json)
echo "Package version: $PACKAGE_VERSION"
# Check if the previous version matches xx.xx.xx format
if [[ "${{ env.PREVIOUS_VERSION }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Previous version format is correct"
else
echo "Previous version format is incorrect"
exit 1
fi
# Split the previous version into major, minor, and patch
IFS='.' read -r MAJOR MINOR PATCH <<<"${{ env.PREVIOUS_VERSION }}"
echo "Previous version components: Major=$MAJOR, Minor=$MINOR, Patch=$PATCH"
# Create the new version
NEW_VERSION="$MAJOR.$MINOR.$((PATCH + 1))"
echo "New version: $NEW_VERSION"
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
# Compare the previous version with the version from package.json
VERSIONS_MATCH=false
if [ "$PACKAGE_VERSION" == "${{ env.NEW_VERSION }}" ]; then
echo "Versions match"
else
echo "Versions do not match, reconciling versions"
# Replace version in package.json with the new version
jq --arg new_version "$NEW_VERSION" '.version = $new_version' package.json > tmp_package.json && mv tmp_package.json package.json
# Read the new version from the updated package.json and echo it
NEW_PACKAGE_VERSION=$(jq -r '.version' package.json)
echo "New package version: $NEW_PACKAGE_VERSION"
echo "Version reconciled successfully"
git config --global user.email "disdainful777@gmail.com"
git config --global user.name "Sinless777"
git pull origin
git add package.json
git commit -m "Update package.json version to $NEW_VERSION"
git push origin
fi
- name: Build the Docker image
run: |
docker build . --file apps/sinlessgames-ui/Dockerfile --tag sinless777/sinlessgames-ui:${{ env.NEW_VERSION }}
- name: Test the Docker image
run: |
docker run -d --name test-container sinless777/sinlessgames-ui:${{ env.NEW_VERSION }}
sleep 10
docker ps | grep test-container
- name: Push the Docker image
run: |
docker tag sinless777/sinlessgames-ui:${{ env.NEW_VERSION }} sinless777/sinlessgames-ui:latest
docker push sinless777/sinlessgames-ui:${{ env.NEW_VERSION }}
docker push sinless777/sinlessgames-ui:latest
- name: Clean up test container
run: |
docker stop test-container
docker rm test-container