-
Notifications
You must be signed in to change notification settings - Fork 8
130 lines (109 loc) · 4.62 KB
/
rust.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
name: "publish"
on:
create:
tags:
- '*'
# This is the example from the readme.
# On each push to the `release` branch it will create or update a GitHub release, build your app, and upload the artifacts to the release.
env:
CARGO_TERM_COLOR: always
BINARIES_LIST: 'ncbi kun_peng'
PROJECT_PREFIX: 'Kun-peng-'
jobs:
build-and-release:
permissions:
contents: write
strategy:
fail-fast: false
matrix:
platform: [macos-latest, ubuntu-20.04, windows-latest, macos-13]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v4
- name: Set Version Number
shell: bash
run: echo "VERSION=$(echo $GITHUB_REF | sed -e 's|refs/tags/||')" >> $GITHUB_ENV
- name: Build
run: cargo build --release
# - name: Install Rust (macOS)
# if: matrix.platform == 'macos-latest'
# run: |
# rustup target add x86_64-apple-darwin
# - name: Build (macOS)
# if: matrix.platform == 'macos-latest'
# run: |
# cargo build --release --target x86_64-apple-darwin
# Set up the GitHub CLI
- name: Install GitHub CLI
run: |
brew install gh
if: matrix.platform == 'macos-latest' || matrix.platform == 'macos-13'
- name: Install GitHub CLI
run: |
sudo apt install -y gh
if: matrix.platform == 'ubuntu-20.04'
- name: Install GitHub CLI
run: |
choco install gh
if: matrix.platform == 'windows-latest'
# Log in to the GitHub CLI
- name: Login to GitHub CLI
run: echo "${{ secrets.GITHUB_TOKEN }}" | gh auth login --with-token
# # Create a release
# - name: Create Release
# id: create_release
# run: |
# gh release create ${{ github.ref_name }} \
# --title "Release ${{ github.ref_name }}" \
# --notes "Release notes for ${{ github.ref_name }}" \
# --draft
# shell: bash
- name: Prepare asset name
run: |
PLATFORM_TAG=$(echo ${{ matrix.platform }} | sed -e 's/macos-latest/macos-arm64/' -e 's/macos-13/macos-x86_64/' -e 's/ubuntu-20.04/linux-x86_64/' -e 's/windows-latest/windows-x86_64/')
echo "ASSET_NAME=${PROJECT_PREFIX}${VERSION}-${PLATFORM_TAG}.tar.gz" >> $GITHUB_ENV
shell: bash
- name: Create tar.gz archive
run: |
mkdir -p ./target/release/packaged
for binary in ${{ env.BINARIES_LIST }}; do
cp "./target/release/$binary" "./target/release/packaged/"
done
tar czvf "./target/release/${{ env.ASSET_NAME }}" -C "./target/release/packaged/" .
shell: bash
- name: Upload Release Asset
run: |
gh release upload ${{ github.ref_name }} \
./target/release/${{ env.ASSET_NAME }} \
--clobber
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
# This step is for building on CentOS 7, only run on ubuntu-latest
- name: Build on CentOS 7
if: matrix.platform == 'ubuntu-20.04'
run: |
docker run --name centos7-container -v $GITHUB_WORKSPACE:/github/workspace -w /github/workspace centos:7 \
/bin/bash -c "echo '[base]' > /etc/yum.repos.d/CentOS-Base.repo; \
echo 'name=CentOS-7 - Base' >> /etc/yum.repos.d/CentOS-Base.repo; \
echo 'baseurl=http://vault.centos.org/centos/7/os/x86_64/' >> /etc/yum.repos.d/CentOS-Base.repo; \
echo 'gpgcheck=1' >> /etc/yum.repos.d/CentOS-Base.repo; \
echo 'enabled=1' >> /etc/yum.repos.d/CentOS-Base.repo; \
echo 'gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7' >> /etc/yum.repos.d/CentOS-Base.repo; \
yum update -y && yum install -y gcc make openssl openssl-devel && \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && export PATH=\$HOME/.cargo/bin:\$PATH && cd /github/workspace && cargo build --release"
mkdir -p ./target/release/packaged_centos7
for binary in $BINARIES_LIST; do
docker cp centos7-container:/github/workspace/target/release/$binary ./target/release/packaged_centos7/
done
tar czvf ./${PROJECT_PREFIX}${VERSION}-centos7.tar.gz -C ./target/release/packaged_centos7 .
docker rm centos7-container
- name: Upload Release Asset for CentOS 7
if: matrix.platform == 'ubuntu-20.04'
run: |
gh release upload ${{ github.ref_name }} \
./${PROJECT_PREFIX}${VERSION}-centos7.tar.gz \
--clobber
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash