aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/build.yml
blob: e73c6f4c5c037514c4b226fbce274097e8110980 (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
# SPDX-FileCopyrightText: 2023 Linnea Gräf <nea@nea.moe>
#
# SPDX-License-Identifier: CC0-1.0

name: Build
on:
    - push
    - pull_request

permissions:
    pull-requests: write

jobs:
    build:
        name: Build
        runs-on: ubuntu-latest
        steps:
            -   uses: actions/checkout@v5
                name: Checkout repository
                with:
                    fetch-tags: true
                    fetch-depth: 0
                    filter: 'tree:0'
            -   uses: ./.github/composite/gradle
            -   name: Build with gradle
                run: |
                    ./gradlew assemble --scan
            -   name: Move build artifact around and print check sum
                run: |
                    rm -f build/libs/*sources*.jar
                    sha256sum build/libs/*.jar
            -   name: Upload build artifact
                uses: actions/upload-artifact@v4
                with:
                    name: built-mod-jar
                    path: build/libs/Firmament-*.jar

    test:
        name: Test
        needs: build
        runs-on: ubuntu-latest
        steps:
            -   uses: actions/checkout@v4
                name: Checkout repository
                with:
                    fetch-tags: true
                    fetch-depth: 0
                    filter: 'tree:0'
            -   uses: ./.github/composite/gradle
            -   name: Build with gradle
                run: |
                    ./gradlew test --scan

    upload:
        name: Upload
        runs-on: ubuntu-latest
        needs: build
        if: ${{ 'push' == github.event_name && ('master' == github.ref_name || startsWith(github.ref_name, 'mc-')) && '637563904' == github.repository_id }}
        steps:
            -   name: Download generated artifact
                uses: actions/download-artifact@v5
                with:
                    name: built-mod-jar
            -   name: Upload to discord
                run: |
                    ls -lahR .
                    curl "$WEBHOOK_URL" -X POST -H "Content-type: multipart/form-data" --form "files[0]=@$(echo *.jar)"
                env:
                    WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }}

    prepare-release:
        name: Prepare a release
        runs-on: ubuntu-22.04
        needs: build
        permissions:
            contents: write
        if: ${{ 'push' == github.event_name && startsWith(github.ref, 'refs/tags/') }}
        steps:
            -   uses: actions/checkout@v5
                name: Checkout repository
                with:
                    fetch-tags: true
                    fetch-depth: 0
                    filter: 'tree:0'

            -   name: Download generated artifact
                uses: actions/download-artifact@v5
                with:
                    name: built-mod-jar
            -   name: Generate changelog
                run: ./docs/generate-changelog.sh > changelog.md

            -   name: Upload release
                env:
                    GH_TOKEN: ${{ github.token }}
                run: |
                    gh release create --draft -t "Firmament ${GITHUB_REF#refs/tags/}" "${GITHUB_REF#refs/tags/}" -F "changelog.md" "*.jar"

            -   name: Notify discord
                env:
                    ACTOR: ${{ github.actor }}
                    WEBHOOK: ${{ secrets.CONFIDENTIAL_WEBHOOK }}
                    REPO: ${{ github.repository }}
                run: |
                    curl -X POST "$WEBHOOK" --data "$(jq -n --arg r "$REPO" --arg v "${GITHUB_REF#refs/tags/}" --arg a "$WEBHOOK" '{"content": ("Created release preview, ready for publishing." + $v+"\n\nSee the draft at https://github.com/"+$r+"/releases/"), "username": $a, "avatar_url": ("https://github.com/" + $a + ".png")}')" -H 'content-type: application/json'