Skip to content

Commit ebd924b

Browse files
authored
ci: update build-and-release-docker-image.yml
1 parent 57380b9 commit ebd924b

File tree

1 file changed

+32
-78
lines changed

1 file changed

+32
-78
lines changed

.github/workflows/build-and-release-docker-image.yml

Lines changed: 32 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -21,86 +21,50 @@ on:
2121
- completed
2222

2323
jobs:
24+
get-version:
25+
runs-on: ubuntu-latest
26+
outputs:
27+
version: ${{ steps.get_version.outputs.version }}
28+
prerelease: ${{ steps.get_version.outputs.prerelease }}
29+
steps:
30+
- uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0
33+
- name: Get version
34+
id: get_version
35+
run: |
36+
VERSION=$(node -p "require('./package.json').version")
37+
VERSION="v$VERSION"
38+
if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ github.event.inputs.release_type }}" == "prerelease" ]]; then
39+
PRERELEASE=true
40+
else
41+
PRERELEASE=false
42+
fi
43+
echo "version=$VERSION" >> $GITHUB_OUTPUT
44+
echo "prerelease=$PRERELEASE" >> $GITHUB_OUTPUT
2445
build-and-push:
46+
needs: get-version
2547
runs-on: ubuntu-latest
2648
steps:
2749
- name: Checkout code
2850
uses: actions/checkout@v4
2951
with:
3052
fetch-depth: 0
31-
3253
- name: Set up QEMU
3354
uses: docker/setup-qemu-action@v3
34-
3555
- name: Set up Docker Buildx
3656
uses: docker/setup-buildx-action@v3
37-
3857
- name: Login to Docker Hub
3958
uses: docker/login-action@v3
4059
with:
4160
username: ${{ secrets.DOCKERHUB_USERNAME }}
4261
password: ${{ secrets.DOCKERHUB_TOKEN }}
43-
44-
- name: Extract version from package.json
45-
id: package-version
46-
run: |
47-
VERSION=$(node -p "require('./package.json').version")
48-
echo "version=$VERSION" >> $GITHUB_OUTPUT
49-
50-
- name: Determine versioning strategy
51-
id: versioning
52-
run: |
53-
BASE_VERSION="v${{ steps.package-version.outputs.version }}"
54-
55-
# Check if tag already exists
56-
if git rev-parse "$BASE_VERSION" >/dev/null 2>&1; then
57-
# Find the highest build number for this version
58-
BUILD_PATTERN="${BASE_VERSION}-"
59-
HIGHEST_BUILD=0
60-
61-
for tag in $(git tag -l "${BUILD_PATTERN}*"); do
62-
# Extract build number from tag
63-
BUILD_NUM=$(echo $tag | sed "s|${BUILD_PATTERN}||")
64-
if [[ "$BUILD_NUM" =~ ^[0-9]+$ ]] && [ $BUILD_NUM -gt $HIGHEST_BUILD ]; then
65-
HIGHEST_BUILD=$BUILD_NUM
66-
fi
67-
done
68-
69-
# Increment for the new build
70-
NEW_BUILD=$((HIGHEST_BUILD + 1))
71-
VERSION="${BASE_VERSION}-${NEW_BUILD}"
72-
echo "New build for existing version: $VERSION"
73-
else
74-
VERSION="$BASE_VERSION"
75-
echo "New version: $VERSION"
76-
fi
77-
78-
echo "full_version=$VERSION" >> $GITHUB_OUTPUT
79-
echo "is_new_base_version=$([[ "$VERSION" == "$BASE_VERSION" ]] && echo "true" || echo "false")" >> $GITHUB_OUTPUT
80-
8162
- name: Login to GitHub Container Registry
8263
uses: docker/login-action@v3
8364
with:
8465
registry: ghcr.io
8566
username: ${{ github.repository_owner }}
8667
password: ${{ secrets.GITHUB_TOKEN }}
87-
88-
- name: Get previous tag
89-
id: previoustag
90-
uses: actions/github-script@v6
91-
with:
92-
script: |
93-
const { data: tags } = await github.rest.repos.listTags({
94-
owner: context.repo.owner,
95-
repo: context.repo.repo,
96-
per_page: 2
97-
});
98-
if (tags.length > 1) {
99-
return tags[1].name;
100-
}
101-
return '';
102-
result-encoding: string
103-
10468
- name: Build and push
10569
uses: docker/build-push-action@v5
10670
with:
@@ -109,14 +73,13 @@ jobs:
10973
push: true
11074
tags: |
11175
joanroig/admincraft-websocket:latest
112-
joanroig/admincraft-websocket:${{ steps.versioning.outputs.full_version }}
76+
joanroig/admincraft-websocket:${{ needs.get-version.outputs.version }}
11377
ghcr.io/${{ github.repository_owner }}/admincraft-websocket:latest
114-
ghcr.io/${{ github.repository_owner }}/admincraft-websocket:${{ steps.versioning.outputs.full_version }}
78+
ghcr.io/${{ github.repository_owner }}/admincraft-websocket:${{ needs.get-version.outputs.version }}
11579
labels: |
11680
org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/admincraft-websocket
11781
org.opencontainers.image.description=Admincraft WebSocket server
118-
org.opencontainers.image.version=${{ steps.versioning.outputs.full_version }}
119-
82+
org.opencontainers.image.version=${{ needs.get-version.outputs.version }}
12083
- name: Update Docker Hub Description
12184
uses: peter-evans/dockerhub-description@v3
12285
with:
@@ -125,30 +88,21 @@ jobs:
12588
repository: joanroig/admincraft-websocket
12689
readme-filepath: ./README.md
12790
short-description: "WebSocket server to control Minecraft Bedrock Dockerized servers with Admincraft"
128-
129-
- name: Create Git Tag
130-
run: |
131-
git config user.name github-actions
132-
git config user.email [email protected]
133-
git tag ${{ steps.versioning.outputs.full_version }}
134-
git push origin ${{ steps.versioning.outputs.full_version }}
135-
echo "Created and pushed tag ${{ steps.versioning.outputs.full_version }}"
136-
13791
- name: Create GitHub Release
13892
id: create_release
13993
uses: actions/create-release@v1
14094
env:
14195
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
14296
with:
143-
tag_name: ${{ steps.versioning.outputs.full_version }}
144-
release_name: Release ${{ steps.versioning.outputs.full_version }}
97+
tag_name: ${{ needs.get-version.outputs.version }}
98+
release_name: Release ${{ needs.get-version.outputs.version }}
14599
draft: false
146-
prerelease: ${{ github.event.inputs.release_type == 'prerelease' }}
100+
prerelease: ${{ needs.get-version.outputs.prerelease }}
147101
body: |
148-
Release ${{ steps.versioning.outputs.full_version }}
102+
Release ${{ needs.get-version.outputs.version }}
149103
150104
Docker images available at:
151-
- Docker Hub: [joanroig/admincraft-websocket:${{ steps.versioning.outputs.full_version }}](https://hub.docker.com/r/joanroig/admincraft-websocket/tags?name=${{ steps.versioning.outputs.full_version }})
152-
- GitHub Packages: [ghcr.io/${{ github.repository_owner }}/admincraft-websocket:${{ steps.versioning.outputs.full_version }}](https://github.com/${{ github.repository_owner }}/admincraft-websocket/pkgs/container/admincraft-websocket)
105+
- Docker Hub: [joanroig/admincraft-websocket:${{ needs.get-version.outputs.version }}](https://hub.docker.com/r/joanroig/admincraft-websocket/tags?name=${{ needs.get-version.outputs.version }})
106+
- GitHub Packages: [ghcr.io/${{ github.repository_owner }}/admincraft-websocket:${{ needs.get-version.outputs.version }}](https://github.com/${{ github.repository_owner }}/admincraft-websocket/pkgs/container/admincraft-websocket)
153107
154-
Full Changelog: https://github.com/${{ github.repository_owner }}/admincraft-websocket/compare/${{ steps.previoustag.outputs.result }}...${{ steps.versioning.outputs.full_version }}
108+
Full Changelog: https://github.com/${{ github.repository_owner }}/admincraft-websocket/compare/HEAD~1...${{ needs.get-version.outputs.version }}

0 commit comments

Comments
 (0)