-
Notifications
You must be signed in to change notification settings - Fork 12
136 lines (119 loc) · 5.36 KB
/
on_issue_version_request.yml
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
name: Build version on issue request
on:
issues:
types: [opened, reopened]
jobs:
check_if_build_needed:
runs-on: ubuntu-latest
outputs:
is_valid_request: ${{ steps.check.outputs.is_valid_request }}
version: ${{ steps.retrieve.outputs.version }}
value: ${{ steps.exist.outputs.value }}
steps:
- id: check
name: Check if issue is a request
run: echo "is_valid_request=${{ startsWith(github.event.issue.title, '[Version request]') }}" >> $GITHUB_OUTPUT
- id: retrieve
name: Retrieve the version from body
if: ${{ steps.check.outputs.is_valid_request == 'true' }}
env:
BODY: ${{ github.event.issue.body }}
run: echo "version="$(echo "$BODY" | tail -n1) >> $GITHUB_OUTPUT
- id: exist
name: Check if version already exists in release
if: ${{ steps.check.outputs.is_valid_request == 'true' }}
run: echo "value="$(gh release view latest --repo ${{ github.repository }} --json assets -q "[.assets.[].name | select(endswith(\"${{ steps.retrieve.outputs.version }}\"))] | length") >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ github.token }}
os_matrix:
needs: check_if_build_needed
name: ${{ matrix.config.name }}
if: ${{ needs.check_if_build_needed.outputs.is_valid_request == 'true' && needs.check_if_build_needed.outputs.value == 0 }}
secrets: inherit
strategy:
fail-fast: false
matrix:
config:
- {
name: Windows,
os: windows-latest
}
- {
name: Linux,
os: ubuntu-latest
}
- {
name: MacOS,
os: macos-latest
}
uses: ./.github/workflows/sniffcraft_build.yml
with:
os: ${{ matrix.config.os }}
version: ${{ needs.check_if_build_needed.outputs.version }}
issue: ${{ github.event.issue.html_url }}
notify_build_started:
runs-on: ubuntu-latest
needs: check_if_build_needed
if: ${{ needs.check_if_build_needed.outputs.is_valid_request == 'true' && needs.check_if_build_needed.outputs.value == 0 }}
steps:
- name: Notify issue
run: gh issue comment ${{ github.event.issue.html_url }} --repo ${{ github.repository }} -b "Build process started. You can follow the build progress [here](https://github.com/${{ github.repository }}/actions) or subscribe to this issue to be notified when binaries are ready."
env:
GH_TOKEN: ${{ github.token }}
notify_already_exists:
runs-on: ubuntu-latest
needs: check_if_build_needed
if: ${{ needs.check_if_build_needed.outputs.is_valid_request == 'true' && needs.check_if_build_needed.outputs.value != 0 }}
steps:
- name: Notify issue
run: |
echo "Binaries for ${{ needs.check_if_build_needed.outputs.version }} are already available in the [latest release](https://github.com/${{ github.repository }}/releases/tag/latest)." > body.txt
echo -en '\n' >> body.txt
echo You can close this issue. If you need an updated build for the same Minecraft version in the future, you can reopen this issue to trigger a new build instead of creating a new one. >> body.txt
gh issue comment ${{ github.event.issue.html_url }} --repo ${{ github.repository }} --body-file body.txt
env:
GH_TOKEN: ${{ github.token }}
update_release:
runs-on: ubuntu-latest
needs:
- check_if_build_needed
- os_matrix
- notify_build_started
steps:
- name: Download Linux artifact
uses: actions/download-artifact@v4
with:
name: sniffcraft-Linux
path: linux
- name: Download Windows artifact
uses: actions/download-artifact@v4
with:
name: sniffcraft-Windows
path: windows
- name: Download macOS artifact
uses: actions/download-artifact@v4
with:
name: sniffcraft-macOS
path: macos
- name: Rename artifacts
run: |
mv linux/sniffcraft sniffcraft-linux-${{ needs.check_if_build_needed.outputs.version }}
mv windows/sniffcraft.exe sniffcraft-windows-${{ needs.check_if_build_needed.outputs.version }}.exe
mv macos/sniffcraft sniffcraft-macos-${{ needs.check_if_build_needed.outputs.version }}
- name: Upload files to release
run: >
gh release upload latest
sniffcraft-linux-${{ needs.check_if_build_needed.outputs.version }}
sniffcraft-windows-${{ needs.check_if_build_needed.outputs.version }}.exe
sniffcraft-macos-${{ needs.check_if_build_needed.outputs.version }}
--repo ${{ github.repository }}
env:
GH_TOKEN: ${{ github.token }}
- name: Comment on associated issue
run: |
echo "New binaries available in the [latest release](https://github.com/${{ github.repository }}/releases/tag/latest) for version ${{ needs.check_if_build_needed.outputs.version }}" > body.txt
echo -en '\n' >> body.txt
echo You can now close this issue. If you need an updated build for the same Minecraft version in the future, you can reopen this issue to trigger a new build instead of creating a new issue. >> body.txt
gh issue comment ${{ github.event.issue.html_url }} --repo ${{ github.repository }} --body-file body.txt
env:
GH_TOKEN: ${{ github.token }}