-
Notifications
You must be signed in to change notification settings - Fork 26
124 lines (105 loc) · 4.43 KB
/
release-build.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
name: Build and Release Rust Project
on:
push:
branches:
- 'release/**' # Trigger on branches matching release/{version}
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
# target: [x86_64-unknown-linux-gnu, x86_64-pc-windows-gnu, x86_64-apple-darwin]
target: [x86_64-unknown-linux-gnu, x86_64-apple-darwin]
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Validate branch name
run: |
BRANCH_NAME="${GITHUB_REF#refs/heads/release/}"
if [[ ! "$BRANCH_NAME" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Branch name must follow semantic versioning (e.g., release/1.0.0)."
exit 1
fi
- name: Extract version from branch name and update Cargo.toml
run: |
VERSION="${GITHUB_REF#refs/heads/release/}"
cd cli
PROJECT_NAME=$(awk -F'=' '/^name/ {gsub(/"/, "", $2); print $2}' Cargo.toml | tr -d ' ')
sed -i.bak "s/^version = \".*\"/version = \"$VERSION\"/" Cargo.toml
echo "PROJECT_NAME=$PROJECT_NAME" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
- name: Install cross
run: cargo install cross
- name: Build with cross
env:
RUSTFLAGS: '-C target-cpu=native'
run: cross build --release --target ${{ matrix.target }} --features jemalloc
- name: Create release directory
run: mkdir -p ${{ github.workspace }}/release/${{ matrix.target }}
- name: Copy binary to release directory
run: cp target/${{ matrix.target }}/release/* ${{ github.workspace }}/release/${{ matrix.target }}/
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.target }}
path: ${{ github.workspace }}/release/${{ matrix.target }}/
create_release:
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Download artifacts
uses: actions/download-artifact@v2
with:
name: x86_64-unknown-linux-gnu
path: ./release/x86_64-unknown-linux-gnu
- name: Download artifacts
uses: actions/download-artifact@v2
with:
name: x86_64-pc-windows-gnu
path: ./release/x86_64-pc-windows-gnu
- name: Download artifacts
uses: actions/download-artifact@v2
with:
name: x86_64-apple-darwin
path: ./release/x86_64-apple-darwin
- name: Prepare release
run: |
ROOT_DIR=$(pwd)
TARGET_DIR="${ROOT_DIR}/documentation/docs/public/releases"
VERSION=${{ env.VERSION }}
VERSION=${VERSION//./-}
PROJECT_NAME=${{ env.PROJECT_NAME }}
# Remove existing version directory if it exists
rm -rf $TARGET_DIR/$PROJECT_NAME/$VERSION
mkdir -p $TARGET_DIR/$PROJECT_NAME
mkdir -p $TARGET_DIR/$PROJECT_NAME/$VERSION
cp ./release/x86_64-unknown-linux-gnu/* $TARGET_DIR/${PROJECT_NAME}_linux_latest
cp ./release/x86_64-pc-windows-gnu/* $TARGET_DIR/${PROJECT_NAME}_windows_latest.exe
cp ./release/x86_64-apple-darwin/* $TARGET_DIR/${PROJECT_NAME}_macos_latest
cp ./release/x86_64-unknown-linux-gnu/* $TARGET_DIR/$PROJECT_NAME/$VERSION/${PROJECT_NAME}_linux
cp ./release/x86_64-pc-windows-gnu/* $TARGET_DIR/$PROJECT_NAME/$VERSION/${PROJECT_NAME}_windows.exe
cp ./release/x86_64-apple-darwin/* $TARGET_DIR/$PROJECT_NAME/$VERSION/${PROJECT_NAME}_macos
- name: Commit and push changes
run: |
git config --global user.name "github-actions"
git config --global user.email "[email protected]"
git add cli/Cargo.toml
git add documentation/docs/public/releases
git commit -m "Release ${{ env.VERSION }}"
git push origin release/${{ env.VERSION }}
- name: Create pull request
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "Release ${{ env.VERSION }}"
branch: release/${{ env.VERSION }}
base: master
title: "Release ${{ env.VERSION }}"
body: "This PR merges release ${{ env.VERSION }} into master and triggers a deploy."