-
Notifications
You must be signed in to change notification settings - Fork 11
170 lines (147 loc) · 6.02 KB
/
main.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
name: Build binaries
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch: {}
jobs:
## Builds artifacts for 3 targets and uploads artifacts
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
- name: Build Windows binary
run: dotnet publish --runtime win-x64 --configuration Release --output artifacts/win-x64 /p:PublishSingleFile=true Floofbot/Floofbot.csproj
- run: zip -j artifacts/win-x64/Floofbot_win-x64.zip artifacts/win-x64/Floofbot.exe artifacts/win-x64/e_sqlite3.dll
- uses: actions/upload-artifact@v2
with:
name: build_artifacts
path: artifacts/win-x64/Floofbot_win-x64.zip
- name: Build Linux binary (full)
run: dotnet publish --runtime linux-x64 --configuration Release --output artifacts/linux-x64 /p:PublishSingleFile=true Floofbot/Floofbot.csproj
- run: tar -czf artifacts/linux-x64/Floofbot_linux-x64.tar.gz -C artifacts/linux-x64 Floofbot libe_sqlite3.so
- uses: actions/upload-artifact@v2
with:
name: build_artifacts
path: artifacts/linux-x64/Floofbot_linux-x64.tar.gz
- name: Build Linux binary (musl)
run: dotnet publish --runtime linux-musl-x64 --configuration Release --output artifacts/linux-musl-x64 /p:PublishSingleFile=true Floofbot/Floofbot.csproj
- run: tar -czf artifacts/linux-musl-x64/Floofbot_linux-musl-x64.tar.gz -C artifacts/linux-musl-x64 Floofbot libe_sqlite3.so
- uses: actions/upload-artifact@v2
with:
name: build_artifacts
path: artifacts/linux-musl-x64/Floofbot_linux-musl-x64.tar.gz
- name: Upload sample config
uses: actions/upload-artifact@v2
with:
name: build_artifacts
path: Floofbot/config.yaml.sample
## Pulls build artifacts and creates a new release from them
release:
needs: build
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
outputs:
new_release_version: ${{ steps.get_new_release_version.outputs.new_version }}
steps:
- name: Get new release version
id: get_new_release_version
shell: bash
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
run: >
curl --silent https://api.github.com/repos/${{ github.repository }}/releases/latest | python3 -c
"import sys, json, datetime;
cur_version = json.load(sys.stdin).get('name', '0.0.0.0').rsplit('.', 1);
new_version = datetime.datetime.utcnow().strftime('%Y.%m.%d'), -1;
base, patch = new_version if new_version[0] != cur_version[0] else cur_version;
print('::set-env name=NEW_VERSION::{0}\n::set-output name=new_version::{0}'.format(f'{base}.{int(patch) + 1}'))"
- name: Download built artifacts
uses: actions/download-artifact@v2
with:
name: build_artifacts
- name: Create release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.NEW_VERSION }}
release_name: ${{ env.NEW_VERSION }}
body: "This release includes changes from the following commits:\n\n${{ join(github.event.commits.*.url, '\n') }}"
draft: false
prerelease: false
- name: Upload release assets (Windows)
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: Floofbot_win-x64.zip
asset_name: Floofbot_win-x64.zip
asset_content_type: application/zip
- name: Upload release assets (Linux)
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: Floofbot_linux-x64.tar.gz
asset_name: Floofbot_linux-x64.tar.gz
asset_content_type: application/gzip
- name: Upload release assets (Linux musl)
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: Floofbot_linux-musl-x64.tar.gz
asset_name: Floofbot_linux-musl-x64.tar.gz
asset_content_type: application/gzip
- name: Upload release assets (config file)
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: config.yaml.sample
asset_name: config.yaml.sample
asset_content_type: text/plain
## Uploads a new Docker image of the build. Requires the release step for the version variable
release_image:
needs: release
runs-on: ubuntu-latest
steps:
- name: Checkout repository for Dockerfile and scripts
uses: actions/checkout@v2
- name: Download built artifacts
uses: actions/download-artifact@v2
with:
name: build_artifacts
- name: Extract build binary
shell: bash
run: 'mkdir -p artifacts/linux-musl-x64 && tar -C artifacts/linux-musl-x64 -xf Floofbot_linux-musl-x64.tar.gz'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker build and push
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: true
build-args: floofbot_version=${{ needs.release.outputs.new_release_version }}
tags: |
ghcr.io/${{ github.repository_owner }}/floofbot:latest
ghcr.io/${{ github.repository_owner }}/floofbot:${{ needs.release.outputs.new_release_version }}