Skip to content

Commit a8d0e07

Browse files
authored
Create github workflow cicd.yml
Let's hope this works
1 parent 7978156 commit a8d0e07

File tree

1 file changed

+151
-0
lines changed

1 file changed

+151
-0
lines changed

.github/workflow/cicd.yml

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
name: deploy
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*'
7+
8+
jobs:
9+
10+
create-windows-binaries:
11+
12+
strategy:
13+
matrix:
14+
conf: [x86_64]
15+
16+
runs-on: windows-latest
17+
18+
steps:
19+
- uses: actions/checkout@v2
20+
21+
- name: Install stable
22+
uses: actions-rs/toolchain@v1
23+
with:
24+
profile: minimal
25+
toolchain: stable
26+
target: ${{ matrix.conf }}-pc-windows-msvc
27+
override: true
28+
29+
- name: Build
30+
run: |
31+
cargo build --release --target ${{ matrix.conf }}-pc-windows-msvc
32+
33+
- name: Get the version
34+
shell: bash
35+
id: tagName
36+
run: |
37+
VERSION=$(cargo pkgid | cut -d# -f2 | cut -d: -f2)
38+
echo "::set-output name=tag::$VERSION"
39+
40+
- name: Build package
41+
id: package
42+
shell: bash
43+
run: |
44+
ARCHIVE_TARGET="${{ matrix.conf }}-pc-windows-msvc"
45+
ARCHIVE_NAME="discord-banner-bot-${{ steps.tagName.outputs.tag }}-$ARCHIVE_TARGET"
46+
ARCHIVE_FILE="${ARCHIVE_NAME}.zip"
47+
7z a ${ARCHIVE_FILE} \
48+
./target/${{ matrix.conf }}-pc-windows-msvc/release/bot.exe \
49+
./README.md
50+
echo "::set-output name=file::${ARCHIVE_FILE}"
51+
echo "::set-output name=name::${ARCHIVE_NAME}.zip"
52+
53+
- name: Upload artifacts
54+
uses: actions/upload-artifact@v2
55+
with:
56+
name: ${{ steps.package.outputs.name }}
57+
path: ${{ steps.package.outputs.file }}
58+
59+
create-unix-binaries:
60+
61+
strategy:
62+
matrix:
63+
os: [ubuntu-latest, macos-latest]
64+
include:
65+
- os: ubuntu-latest
66+
target: x86_64-unknown-linux-musl
67+
- os: macos-latest
68+
target: x86_64-apple-darwin
69+
70+
runs-on: ${{ matrix.os }}
71+
72+
steps:
73+
- uses: actions/checkout@v2
74+
75+
- name: Install Rust
76+
uses: actions-rs/toolchain@v1
77+
with:
78+
profile: minimal
79+
toolchain: stable
80+
target: ${{ matrix.target }}
81+
override: true
82+
83+
- name: Install musl
84+
if: contains(matrix.target, 'linux-musl')
85+
run: |
86+
sudo apt-get install musl-tools
87+
88+
- name: Build
89+
run: |
90+
cargo build --release --target ${{ matrix.target }}
91+
92+
- name: Strip binary
93+
run: |
94+
strip target/${{ matrix.target }}/release/bot
95+
96+
- name: Get the version
97+
id: tagName
98+
run: |
99+
VERSION=$(cargo pkgid | cut -d# -f2 | cut -d: -f2)
100+
echo "::set-output name=tag::$VERSION"
101+
102+
- name: Build package
103+
id: package
104+
run: |
105+
ARCHIVE_TARGET=${{ matrix.target }}
106+
ARCHIVE_NAME="discord-banner-bot-${{ steps.tagName.outputs.tag }}-$ARCHIVE_TARGET"
107+
ARCHIVE_FILE="${ARCHIVE_NAME}.tar.gz"
108+
mkdir "/tmp/${ARCHIVE_NAME}"
109+
cp README.md \
110+
target/${{ matrix.target }}/release/bot \
111+
/tmp/${ARCHIVE_NAME}
112+
tar -czf ${PWD}/${ARCHIVE_FILE} -C /tmp/ ${ARCHIVE_NAME}
113+
echo ::set-output "name=file::${ARCHIVE_FILE}"
114+
echo ::set-output "name=name::${ARCHIVE_NAME}.tar.gz"
115+
116+
- name: Upload artifacts
117+
uses: actions/upload-artifact@v2
118+
with:
119+
name: ${{ steps.package.outputs.name }}
120+
path: ${{ steps.package.outputs.file }}
121+
122+
123+
deploy:
124+
125+
needs: [create-windows-binaries, create-unix-binaries]
126+
127+
runs-on: ubuntu-latest
128+
129+
steps:
130+
- uses: actions/checkout@v2
131+
132+
- name: Get version and release description
133+
id: tagName
134+
run: |
135+
VERSION=$(cargo pkgid | cut -d# -f2 | cut -d: -f2)
136+
echo "::set-output name=tag::$VERSION"
137+
138+
- name: Download artifacts
139+
uses: actions/download-artifact@v2
140+
with:
141+
path: ./binaries
142+
143+
- name: Create a release
144+
uses: softprops/action-gh-release@v1
145+
with:
146+
name: v${{ steps.tagName.outputs.tag }}
147+
files: |
148+
./binaries/**/*.zip
149+
./binaries/**/*.tar.gz
150+
env:
151+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)