-
Notifications
You must be signed in to change notification settings - Fork 0
178 lines (155 loc) · 5.72 KB
/
build_and_release.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
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
name: CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: goto-bus-stop/setup-zig@v2
with:
version: 0.13.0
- run: zig fmt --check .
build:
permissions: write-all
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
include:
- os: ubuntu-latest
target: x86_64-linux
- os: macos-latest
target: aarch64-macos-none
- os: windows-latest
target: x86_64-windows
runs-on: ${{ matrix.os }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v2
- name: Get commit hash
id: commit
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
- uses: goto-bus-stop/setup-zig@v2
name: Setup zig
with:
version: 0.13.0
- name: Install dependencies (Ubuntu)
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get update && sudo apt-get install -y libgl1-mesa-dev libx11-dev libgtk-4-dev build-essential
- name: Set SDKROOT (macOS)
if: matrix.os == 'macos-latest'
run: echo "export SDKROOT=$(xcrun --show-sdk-path)" >> $GITHUB_ENV
- name: Get universal dependencies
run: zig fetch --save https://github.com/Not-Nik/raylib-zig/archive/devel.tar.gz
- name: Build binary
run: zig build -Doptimize=ReleaseSafe
- name: Prepare binary (MacOS, Ubuntu)
if: matrix.os != 'windows-latest'
run: |
chmod +x zig-out/bin/DiaB-concept
mv zig-out/bin/DiaB-concept zig-out/bin/DiaB-concept_${{ matrix.os }}-${{ matrix.target }}
- name: Prepare binary (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
$binary = Get-ChildItem -Path zig-out\bin -Filter *.exe | Select-Object -First 1
if ($binary) {
$newName = "DiaB-concept_${{ matrix.os }}-${{ matrix.target }}.exe"
Rename-Item -Path $binary.FullName -NewName $newName
Write-Output "Renamed $($binary.Name) to $newName"
} else {
Write-Error "No .exe file found in zig-out\bin"
exit 1
}
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: DiaB-concept_${{ matrix.os }}-${{ matrix.target }}
path: zig-out/bin/DiaB-concept_${{ matrix.os }}-${{ matrix.target }}${{ matrix.os == 'windows-latest' && '.exe' || '' }}
if-no-files-found: error
release:
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
permissions:
contents: write
issues: write
pull-requests: write
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Download all artifacts
uses: actions/download-artifact@v2
- name: Determine release type
id: release_type
run: |
# Check for #major, #minor, #patch in the latest commit message
COMMIT_MSG=$(git log -1 --pretty=%B)
if [[ $COMMIT_MSG == *#major* ]]; then
echo "type=major" >> $GITHUB_OUTPUT
elif [[ $COMMIT_MSG == *#minor* ]]; then
echo "type=minor" >> $GITHUB_OUTPUT
elif [[ $COMMIT_MSG == *#patch* ]]; then
echo "type=patch" >> $GITHUB_OUTPUT
else
# Default to patch if not specified
echo "type=patch" >> $GITHUB_OUTPUT
fi
- name: Get version
id: get_version
run: |
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "Latest tag: $LATEST_TAG"
# Remove 'v' prefix
VERSION=${LATEST_TAG#v}
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"
#MAJOR=0
#MINOR=0
#PATCH=0
RELEASE_TYPE="${{ steps.release_type.outputs.type }}"
echo "Release type: $RELEASE_TYPE"
if [[ $RELEASE_TYPE == "major" ]]; then
NEW_VERSION="$((MAJOR+1)).0.0"
elif [[ $RELEASE_TYPE == "minor" ]]; then
NEW_VERSION="$MAJOR.$((MINOR+1)).0"
else
NEW_VERSION="$MAJOR.$MINOR.$((PATCH+1))"
fi
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION"
- name: Create tag
env:
NEW_VERSION: ${{ steps.get_version.outputs.new_version }}
run: |
echo "Creating tag v$NEW_VERSION"
git config user.name github-actions
git config user.email github-actions@github.com
git tag -a v$NEW_VERSION -m "Release v$NEW_VERSION"
git push origin v$NEW_VERSION
- name: Release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NEW_VERSION: ${{ steps.get_version.outputs.new_version }}
with:
tag_name: v${{ env.NEW_VERSION }}
name: Release v${{ env.NEW_VERSION }}
files: ./**/DiaB-concept_*
generate_release_notes: true
- name: Debug
if: failure()
run: |
echo "GITHUB_TOKEN permissions:"
curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/${{ github.repository }}/actions/permissions
echo "Current user:"
curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/user
echo "Environment variables:"
env
echo "GitHub context:"
echo '${{ toJson(github) }}'