-
Notifications
You must be signed in to change notification settings - Fork 0
159 lines (145 loc) · 4.61 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
name: "publish"
on:
pull_request:
types:
- opened
branches:
- 'main'
- 'releases/**'
paths:
- '**.rs'
jobs:
create-release:
permissions:
contents: write
runs-on: ubuntu-20.04
outputs:
release_id: ${{ steps.create-release.outputs.result }}
steps:
- uses: actions/checkout@v4
- name: get version
uses: SebRollen/toml-action@v1.2.0
id: read_toml
with:
file: "Cargo.toml"
field: "package.version"
- name: create release
id: create-release
uses: actions/github-script@v7
with:
script: |
const { data } = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: `tg_banana_bot_v${{steps.read_toml.outputs.value}}`,
name: `Telegram Banana Bot v${{steps.read_toml.outputs.value}}`,
body: `${{ github.event.head_commit.message }}`,
draft: true,
prerelease: false
})
return data.id
build-app:
needs: create-release
permissions:
contents: write
strategy:
matrix:
build: [linux, macos, windows]
include:
- build: linux
os: ubuntu-22.04
rust: nightly
target: x86_64-unknown-linux-gnu
archive-name: tg-banana-bot-linux.tar.gz
- build: macos
os: macos-latest
rust: nightly
target: x86_64-apple-darwin
archive-name: tg-banana-bot-macos.tar.gz
- build: windows
os: windows-latest
rust: nightly-x86_64-msvc
target: x86_64-pc-windows-msvc
archive-name: tg-banana-bot-windows.7z
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: get name
uses: SebRollen/toml-action@v1.2.0
id: read_toml
with:
file: "Cargo.toml"
field: "package.name"
- name: Install Rust
uses: actions-rs/toolchain@v1.0.6
with:
toolchain: ${{ matrix.rust }}
profile: minimal
override: true
target: ${{ matrix.target }}
- name: Install libssl-dev
shell: bash
run: |
if [ "${{ matrix.build }}" = "linux" ]; then
sudo apt-get install -y pkg-config libssl-dev
fi
- name: Build binary
run: cargo build --verbose --release --target ${{ matrix.target }}
env:
RUST_BACKTRACE: 1
- name: Build archive
shell: bash
run: |
mkdir archive
cp LICENSE README.md archive/
cd archive
if [ "${{ matrix.build }}" = "windows" ]; then
cp "../target/${{ matrix.target }}/release/${{steps.read_toml.outputs.value}}.exe" ./
7z a "${{ matrix.archive-name }}" LICENSE README.md ${{steps.read_toml.outputs.value}}.exe
else
cp "../target/${{ matrix.target }}/release/${{steps.read_toml.outputs.value}}" ./
tar -czf "${{ matrix.archive-name }}" LICENSE README.md ${{steps.read_toml.outputs.value}}
fi
ls -a
- name: upload release asset
uses: actions/github-script@v7
env:
release_id: ${{ needs.create-release.outputs.release_id }}
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('node:fs')
github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: process.env.release_id,
name: '${{ matrix.archive-name }}',
data: await fs.readFileSync('./archive/${{ matrix.archive-name }}'),
})
# - name: Upload archive
# uses: actions/upload-artifact@v1
# with:
# name: ${{ matrix.archive-name }}
# path: archive/${{ matrix.archive-name }}
publish-release:
permissions:
contents: write
runs-on: ubuntu-20.04
needs: [create-release, build-app]
steps:
- name: publish release
id: publish-release
uses: actions/github-script@v7
env:
release_id: ${{ needs.create-release.outputs.release_id }}
with:
script: |
github.rest.repos.updateRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: process.env.release_id,
draft: false,
prerelease: false
})