21
21
- completed
22
22
23
23
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
24
45
build-and-push :
46
+ needs : get-version
25
47
runs-on : ubuntu-latest
26
48
steps :
27
49
- name : Checkout code
28
50
uses : actions/checkout@v4
29
51
with :
30
52
fetch-depth : 0
31
-
32
53
- name : Set up QEMU
33
54
uses : docker/setup-qemu-action@v3
34
-
35
55
- name : Set up Docker Buildx
36
56
uses : docker/setup-buildx-action@v3
37
-
38
57
- name : Login to Docker Hub
39
58
uses : docker/login-action@v3
40
59
with :
41
60
username : ${{ secrets.DOCKERHUB_USERNAME }}
42
61
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
-
81
62
- name : Login to GitHub Container Registry
82
63
uses : docker/login-action@v3
83
64
with :
84
65
registry : ghcr.io
85
66
username : ${{ github.repository_owner }}
86
67
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
-
104
68
- name : Build and push
105
69
uses : docker/build-push-action@v5
106
70
with :
@@ -109,14 +73,13 @@ jobs:
109
73
push : true
110
74
tags : |
111
75
joanroig/admincraft-websocket:latest
112
- joanroig/admincraft-websocket:${{ steps.versioning .outputs.full_version }}
76
+ joanroig/admincraft-websocket:${{ needs.get-version .outputs.version }}
113
77
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 }}
115
79
labels : |
116
80
org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/admincraft-websocket
117
81
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 }}
120
83
- name : Update Docker Hub Description
121
84
uses : peter-evans/dockerhub-description@v3
122
85
with :
@@ -125,30 +88,21 @@ jobs:
125
88
repository : joanroig/admincraft-websocket
126
89
readme-filepath : ./README.md
127
90
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
-
137
91
- name : Create GitHub Release
138
92
id : create_release
139
93
uses : actions/create-release@v1
140
94
env :
141
95
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
142
96
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 }}
145
99
draft : false
146
- prerelease : ${{ github.event.inputs.release_type == ' prerelease' }}
100
+ prerelease : ${{ needs.get-version.outputs. prerelease }}
147
101
body : |
148
- Release ${{ steps.versioning .outputs.full_version }}
102
+ Release ${{ needs.get-version .outputs.version }}
149
103
150
104
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)
153
107
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