Skip to content

Commit 4d63081

Browse files
committed
add github workflow
1 parent 9d004f9 commit 4d63081

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed

.github/workflow/build.yml

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: Build neko
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
branches:
8+
- main
9+
jobs:
10+
build_windows:
11+
runs-on: windows-latest
12+
steps:
13+
- uses: actions/checkout@v1
14+
- name: Build (All features)
15+
run: |
16+
cd neko
17+
cargo build --locked --release --all-features
18+
- name: Upload neko
19+
uses: actions/upload-artifact@v1
20+
with:
21+
name: neko-windows
22+
path: ./target/release/neko.exe
23+
build_mac:
24+
runs-on: macos-latest
25+
steps:
26+
- uses: actions/checkout@v1
27+
- name: Install Rust
28+
run: curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
29+
- name: Build (All features)
30+
run: |
31+
source $HOME/.cargo/env
32+
cd neko
33+
cargo build --locked --release --all-features
34+
- name: Upload neko
35+
uses: actions/upload-artifact@v1
36+
with:
37+
name: neko-macos
38+
path: ./target/release/neko
39+
build_linux:
40+
runs-on: ubuntu-latest
41+
steps:
42+
- uses: actions/checkout@v1
43+
- name: Build (All features)
44+
run: |
45+
cd neko
46+
cargo build --locked --release --all-features
47+
- name: Upload neko
48+
uses: actions/upload-artifact@v1
49+
with:
50+
name: neko-linux
51+
path: ./target/release/neko
52+
release:
53+
runs-on: ubuntu-latest
54+
needs: ['build_windows', 'build_mac', 'build_linux']
55+
if: contains(github.event.head_commit.message, '[release]')
56+
steps:
57+
- uses: actions/checkout@v1
58+
- name: Download artifacts
59+
uses: actions/download-artifact@v2
60+
with:
61+
path: artifacts
62+
- run: |
63+
zip -rj neko-linux.zip ./artifacts/neko-linux/*
64+
zip -rj neko-macos.zip ./artifacts/neko-macos/*
65+
zip -rj neko-windows.zip ./artifacts/neko-windows/*
66+
67+
VERSION=`grep -Po '(?<=^version = ")([^"]+)' ./neko/Cargo.toml`
68+
echo "VERSION=$VERSION" >> $GITHUB_ENV
69+
- name: Get changelog
70+
run: |
71+
CHANGELOG_ENTRY=`grep --color=never -m 1 -Po '## \K(\[[0-9\.]+\])' CHANGELOG.md`
72+
DESCRIPTION=`bash ./extract-changelog.sh $CHANGELOG_ENTRY`
73+
74+
echo "CHANGELOG_ENTRY=$CHANGELOG_ENTRY" >> $GITHUB_ENV
75+
76+
echo "CHANGELOG_DESCRIPTION<<EOF" >> $GITHUB_ENV
77+
echo "$DESCRIPTION" >> $GITHUB_ENV
78+
echo "EOF" >> $GITHUB_ENV
79+
- name: Create release
80+
id: create_release
81+
uses: actions/create-release@v1
82+
env:
83+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84+
with:
85+
tag_name: ${{ env.VERSION }}
86+
release_name: ${{ env.CHANGELOG_ENTRY }}
87+
body: ${{ env.CHANGELOG_DESCRIPTION }}
88+
draft: true
89+
- name: Upload Linux build
90+
uses: actions/upload-release-asset@v1
91+
env:
92+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
93+
with:
94+
upload_url: ${{ steps.create_release.outputs.upload_url }}
95+
asset_path: ./neko-linux.zip
96+
asset_name: neko-${{ env.VERSION }}-linux.zip
97+
asset_content_type: application/zip
98+
- name: Upload Windows build
99+
uses: actions/upload-release-asset@v1
100+
env:
101+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
102+
with:
103+
upload_url: ${{ steps.create_release.outputs.upload_url }}
104+
asset_path: ./neko-windows.zip
105+
asset_name: neko-${{ env.VERSION }}-windows.zip
106+
asset_content_type: application/zip
107+
- name: Upload Mac build
108+
uses: actions/upload-release-asset@v1
109+
env:
110+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
111+
with:
112+
upload_url: ${{ steps.create_release.outputs.upload_url }}
113+
asset_path: ./neko-macos.zip
114+
asset_name: neko-${{ env.VERSION }}-macos.zip
115+
asset_content_type: application/zip

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
## [0.1.0]
2+
- Initial release

extract-changelog.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
# Extracts the changelog of the version provided from CHANGELOG.md
3+
startReadingChangelog=false
4+
5+
while IFS= read -r line; do
6+
if [[ $line == "## $1"* ]]; then
7+
startReadingChangelog=true
8+
elif $startReadingChangelog; then
9+
if [[ $line == "## "* ]]; then
10+
exit
11+
else
12+
echo $line
13+
fi
14+
fi
15+
done < "CHANGELOG.md"

0 commit comments

Comments
 (0)