summaryrefslogtreecommitdiff
path: root/.github/workflows/release.yml
blob: 4b42e62c9ba36dd8c9273b013922a25a25127e46 (plain)
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
name: Release

on:
  push:
    branches:
      - master

env:
  REGISTRY_IMAGE: pugmatt/bedrock-connect

jobs:
  release:

    runs-on: ubuntu-latest
    outputs:
      RELEASE_VERSION: ${{ steps.outputs.outputs.RELEASE_VERSION }}
      MINECRAFT_VERSION: ${{ steps.outputs.outputs.MINECRAFT_VERSION }}
      NEW_RELEASE: ${{ steps.outputs.outputs.NEW_RELEASE }}

    steps:
    - uses: actions/checkout@v4

    - name: Set Env
      env:
        COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
      run: |
        echo "RELEASE_VERSION=$(python .github/assets/versionUp.py)" >> $GITHUB_ENV
        echo "MINECRAFT_VERSION=${{ vars.SUPPORTED_VERSION }}" >> $GITHUB_ENV
        echo "NEW_RELEASE=$(python .github/assets/pattern_check.py "$COMMIT_MESSAGE")" >> $GITHUB_ENV

    - name: Output env
      id: outputs
      run: |
        echo "RELEASE_VERSION=${{ env.RELEASE_VERSION }}" >> $GITHUB_OUTPUT
        echo "MINECRAFT_VERSION=${{ env.MINECRAFT_VERSION }}" >> $GITHUB_OUTPUT
        echo "NEW_RELEASE=${{ env.NEW_RELEASE }}" >> $GITHUB_OUTPUT

    - name: Set up OpenJDK
      uses: actions/setup-java@v4
      with:
        java-version: '21'
        distribution: 'adopt'
        cache: maven

    - name: Build with maven
      run: |
        cd serverlist-server
        mvn -B package

    - name: Upload artifact
      uses: actions/upload-artifact@v4
      with:
        name: build-artifact
        path: ./serverlist-server/target/BedrockConnect-1.0-SNAPSHOT.jar
        if-no-files-found: error

    - name: Make release artifacts
      if: env.NEW_RELEASE == 'True'
      run: |
        mkdir setup-zip
        cp .github/assets/run.bat setup-zip/run.bat && cp .github/assets/README.txt setup-zip/README.txt && cp serverlist-server/target/BedrockConnect-1.0-SNAPSHOT.jar setup-zip/BedrockConnect-1.0-SNAPSHOT.jar
        cd setup-zip
        zip -r ../BedrockConnect-setup.zip .
        cd ..
        rm -rf setup-zip

    - name: create release
      if: env.NEW_RELEASE == 'True'
      id: create_release
      uses: actions/create-release@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        tag_name: ${{ env.RELEASE_VERSION }}
        release_name: ${{ github.event.head_commit.message }}
        draft: false
        prerelease: false

    - name: Upload Release Asset 1
      if: env.NEW_RELEASE == 'True'
      id: upload-release-asset1
      uses: actions/upload-release-asset@v1.0.1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        upload_url: ${{ steps.create_release.outputs.upload_url }}
        asset_path: ./BedrockConnect-setup.zip
        asset_name: BedrockConnect-setup.zip
        asset_content_type: application/zip

    - name: Upload Release Asset 2
      if: env.NEW_RELEASE == 'True'
      id: upload-release-asset2
      uses: actions/upload-release-asset@v1.0.1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        upload_url: ${{ steps.create_release.outputs.upload_url }}
        asset_path: ./serverlist-server/target/BedrockConnect-1.0-SNAPSHOT.jar
        asset_name: BedrockConnect-1.0-SNAPSHOT.jar
        asset_content_type: application/java-archive

  docker:
    runs-on: ubuntu-latest
    needs:
      - release
    strategy:
      fail-fast: false
      matrix:
        platform:
          - linux/amd64
          - linux/arm64

    steps:
      - name: Prepare
        run: |
          platform=${{ matrix.platform }}
          echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV

      - uses: actions/checkout@v4

      - name: Download jar
        uses: actions/download-artifact@v4
        with:
          name: build-artifact
          path: ./serverlist-server/target/BedrockConnect-1.0-SNAPSHOT.jar

      - name: Docker meta
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: ${{ env.REGISTRY_IMAGE }}

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Login to Docker Hub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Build and push
        id: build
        uses: docker/build-push-action@v5
        with:
          context: serverlist-server
          push: true
          platforms: ${{ matrix.platform }}
          labels: ${{ steps.meta.outputs.labels }}
          outputs: type=image,name=${{ env.REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true

      - name: Export digest
        run: |
          mkdir -p /tmp/digests
          digest="${{ steps.build.outputs.digest }}"
          touch "/tmp/digests/${digest#sha256:}"
      - name: Upload digest
        uses: actions/upload-artifact@v4
        with:
          name: digests-${{ env.PLATFORM_PAIR }}
          path: /tmp/digests/*
          if-no-files-found: error
          retention-days: 1

  push:
    runs-on: ubuntu-latest
    needs:
      - release
      - docker
    env:
      NEW_RELEASE: ${{ needs.release.outputs.NEW_RELEASE }}
      RELEASE_VERSION: ${{ needs.release.outputs.RELEASE_VERSION }}

    steps:
      - name: Download digests
        uses: actions/download-artifact@v4
        with:
          path: /tmp/digests
          pattern: digests-*
          merge-multiple: true

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Update docker version
        if: env.NEW_RELEASE == 'True'
        run: echo "DOCKER_VERSION=${{ needs.release.outputs.RELEASE_VERSION }}" >> $GITHUB_ENV

      - name: Update docker version dev
        if: env.NEW_RELEASE == 'False'
        run: echo "DOCKER_VERSION=dev" >> $GITHUB_ENV

      - name: Docker meta
        id: meta
        uses: docker/metadata-action@v5
        with:
          images: ${{ env.REGISTRY_IMAGE }}
          tags: |
            ${{ env.DOCKER_VERSION }}
            ${{ env.NEW_RELEASE == 'True' && 'latest' || '' }}

      - name: Login to Docker Hub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}

      - name: Create manifest list and push
        working-directory: /tmp/digests
        run: |
          docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
            $(printf '${{ env.REGISTRY_IMAGE }}@sha256:%s ' *)

      - name: Inspect image
        run: |
          docker buildx imagetools inspect ${{ env.REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}