summaryrefslogtreecommitdiff
path: root/.github/workflows/_release.yaml
blob: 6d2e563cd519450ee701c4fe0aa55774ca86f4f6 (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
name: Release (shared)

on:
  workflow_call:
    inputs:
      platform:
        description: "paper or velocity"
        required: true
        type: string
      modrinth-game-versions:
        description: "Newline-separated Minecraft versions listed on Modrinth"
        required: true
        type: string
      modrinth-mc-version:
        description: "Minecraft version shown in the Modrinth version name (paper only)"
        required: false
        type: string
        default: ""
    secrets:
      MODRINTH_TOKEN:
        required: true
      MODRINTH_PROJECT_ID:
        required: true

jobs:
  validate:
    runs-on: ubuntu-24.04
    outputs:
      version: ${{ steps.get_version.outputs.version }}
      jar_name: ${{ steps.get_version.outputs.jar_name }}
      module: ${{ steps.get_version.outputs.module }}
      label: ${{ steps.get_version.outputs.label }}
      modrinth_name: ${{ steps.get_version.outputs.modrinth_name }}
      modrinth_version: ${{ steps.get_version.outputs.modrinth_version }}
      modrinth_loaders: ${{ steps.get_version.outputs.modrinth_loaders }}
    steps:
      - name: Checkout repository
        uses: actions/checkout@v6

      - name: Extract version from tag and validate
        id: get_version
        env:
          PLATFORM: ${{ inputs.platform }}
          MC_VERSION: ${{ inputs.modrinth-mc-version }}
        run: |
          # Paper keeps the bare vX.Y.Z tag so that UpdateChecker in already-deployed
          # Paper builds, which strips only a leading "v", keeps recognising new releases.
          case "$PLATFORM" in
            paper)
              TAG_PREFIX="v"
              VERSION_KEY="paperVersion"
              JAR_SUFFIX=""
              MODULE="platform-paper"
              LABEL="Paper/Folia"
              ;;
            velocity)
              TAG_PREFIX="velocity/v"
              VERSION_KEY="velocityVersion"
              JAR_SUFFIX="-velocity"
              MODULE="platform-velocity"
              LABEL="Velocity"
              ;;
            *)
              echo "Error: unknown platform '$PLATFORM'"
              exit 1
              ;;
          esac

          TAG_NAME=${GITHUB_REF#refs/tags/}
          if [[ ! "$TAG_NAME" =~ ^${TAG_PREFIX}[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
            echo "Error: Tag $TAG_NAME does not match ${TAG_PREFIX}X.Y.Z"
            exit 1
          fi

          TAG_VERSION=${TAG_NAME#"$TAG_PREFIX"}
          GRADLE_VERSION=$(grep "^${VERSION_KEY}=" gradle.properties | cut -d'=' -f2)
          if [ "$TAG_VERSION" != "$GRADLE_VERSION" ]; then
            echo "Error: Tag version ($TAG_VERSION) does not match gradle.properties $VERSION_KEY ($GRADLE_VERSION)"
            exit 1
          fi

          if [ "$PLATFORM" = "paper" ]; then
            MODRINTH_NAME="v${TAG_VERSION} (${LABEL} v${MC_VERSION})"
            MODRINTH_VERSION="$TAG_VERSION"
            MODRINTH_LOADERS=$'paper\nfolia'
          else
            MODRINTH_NAME="v${TAG_VERSION} (${LABEL})"
            MODRINTH_VERSION="${TAG_VERSION}-velocity"
            MODRINTH_LOADERS="velocity"
          fi

          {
            echo "version=$TAG_VERSION"
            echo "jar_name=LunaticChat-${TAG_VERSION}${JAR_SUFFIX}.jar"
            echo "module=$MODULE"
            echo "label=$LABEL"
            echo "modrinth_name=$MODRINTH_NAME"
            echo "modrinth_version=$MODRINTH_VERSION"
            echo "modrinth_loaders<<EOF"
            echo "$MODRINTH_LOADERS"
            echo "EOF"
          } >> "$GITHUB_OUTPUT"
          echo "Version validation passed: $TAG_NAME"

      - name: Check if release already exists
        env:
          GH_TOKEN: ${{ github.token }}
        run: |
          TAG_NAME=${GITHUB_REF#refs/tags/}
          if gh release view "$TAG_NAME" &> /dev/null; then
            echo "Error: Release $TAG_NAME already exists"
            exit 1
          fi
          echo "Release validation passed: $TAG_NAME does not exist yet"

  build:
    runs-on: ubuntu-24.04
    needs: validate
    steps:
      - name: Checkout repository
        uses: actions/checkout@v6

      - name: Setup Development Environment
        uses: jdx/mise-action@v4

      - name: Setup Gradle
        uses: gradle/actions/setup-gradle@v6

      - name: Grant execute permission for gradlew
        run: chmod +x gradlew

      - name: Build shadowJar
        run: ./gradlew :${{ needs.validate.outputs.module }}:shadowJar --no-daemon

      - name: Upload build artifact
        uses: actions/upload-artifact@v7
        with:
          name: LunaticChat-${{ inputs.platform }}-v${{ needs.validate.outputs.version }}
          path: ${{ needs.validate.outputs.module }}/build/libs/${{ needs.validate.outputs.jar_name }}
          retention-days: 90

  release:
    runs-on: ubuntu-24.04
    needs: [validate, build]
    permissions:
      contents: write
    steps:
      - name: Checkout repository
        uses: actions/checkout@v6

      - name: Download build artifact
        uses: actions/download-artifact@v8
        with:
          name: LunaticChat-${{ inputs.platform }}-v${{ needs.validate.outputs.version }}
          path: ${{ needs.validate.outputs.module }}/build/libs

      # Created as a draft, so "latest" is decided when it is published, not here:
      # GitHub makes a newly published release the latest one unless told otherwise.
      - name: Create GitHub Release
        env:
          GH_TOKEN: ${{ github.token }}
          PLATFORM: ${{ inputs.platform }}
          VERSION: ${{ needs.validate.outputs.version }}
          JAR_PATH: ${{ needs.validate.outputs.module }}/build/libs/${{ needs.validate.outputs.jar_name }}
          LABEL: ${{ needs.validate.outputs.label }}
        run: |
          TAG_NAME=${GITHUB_REF#refs/tags/}

          # The notes point at the changelog on the documentation site rather than
          # repeating it here, so the release notes live in exactly one place.
          gh release create "$TAG_NAME" \
            "$JAR_PATH" \
            --title "v${VERSION} (${LABEL})" \
            --draft \
            --notes "Release notes: [${LABEL} v${VERSION}](https://lc.m1sk9.dev/changelog/${PLATFORM}/v${VERSION})"

      - name: Publish to Modrinth
        uses: cloudnode-pro/modrinth-publish@3870f66007063f03fb70118ca9eddbc09a4ba666 # v2
        with:
          token: ${{ secrets.MODRINTH_TOKEN }}
          name: ${{ needs.validate.outputs.modrinth_name }}
          project: ${{ secrets.MODRINTH_PROJECT_ID }}
          version: ${{ needs.validate.outputs.modrinth_version }}
          channel: release
          changelog: |-
            Please refer to the [release notes](https://lc.m1sk9.dev/changelog/${{ inputs.platform }}/v${{ needs.validate.outputs.version }}) for update details.
          loaders: ${{ needs.validate.outputs.modrinth_loaders }}
          game-versions: ${{ inputs.modrinth-game-versions }}
          files: ${{ needs.validate.outputs.module }}/build/libs/${{ needs.validate.outputs.jar_name }}