-
Notifications
You must be signed in to change notification settings - Fork 26
172 lines (152 loc) · 6.41 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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
name: Build and Release Rust Project
on:
push:
branches:
- 'release/**' # Trigger on branches matching release/{version}
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
include:
- os: ubuntu-latest
extension: ""
shell: bash
- os: macos-latest
extension: ""
shell: bash
- os: windows-latest
extension: ".exe"
shell: pwsh
rust: [stable]
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Validate branch name
id: validate_branch
shell: ${{ matrix.shell }}
run: |
if [ "${{ matrix.os }}" == "windows-latest" ]; then
$BRANCH_NAME = $env:GITHUB_REF -replace 'refs/heads/release/', ''
if ($BRANCH_NAME -notmatch '^[0-9]+\.[0-9]+\.[0-9]+$') {
Write-Error "Error: Branch name must follow semantic versioning (e.g., release/1.0.0)."
exit 1
}
else
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
fi
- name: Extract version from branch name and update Cargo.toml
id: update_version
shell: ${{ matrix.shell }}
run: |
if [ "${{ matrix.os }}" == "windows-latest" ]; then
cd cli
$VERSION = $env:GITHUB_REF -replace 'refs/heads/release/', ''
$PROJECT_NAME = (Select-String -Path 'Cargo.toml' -Pattern '^name' -SimpleMatch).Matches.Groups[2].Value.Trim('"')
(Get-Content Cargo.toml) -replace 'version = ".*"', 'version = "' + $VERSION + '"' | Set-Content Cargo.toml
echo "PROJECT_NAME=$PROJECT_NAME" >> $env:GITHUB_ENV
echo "VERSION=$VERSION" >> $env:GITHUB_ENV
else
cd cli
VERSION="${GITHUB_REF#refs/heads/release/}"
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
fi
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.rust }}
override: true
- name: Cache Cargo registry
uses: actions/cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Cache Cargo build
uses: actions/cache@v2
with:
path: target
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-build-
- name: Build
run: |
cd cli
RUSTFLAGS='-C target-cpu=native' cargo build --release --features jemalloc
- name: Create release directory
run: mkdir -p ${{ github.workspace }}/release
- name: Copy binary to release directory
run: |
cd cli
cp target/release/${{ env.PROJECT_NAME }}${{ matrix.extension }} ${{ github.workspace }}/release/${{ env.PROJECT_NAME }}_${{ matrix.os }}_latest${{ matrix.extension }}
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: ${{ env.PROJECT_NAME }}-${{ env.VERSION }}-${{ matrix.os }}
path: ${{ github.workspace }}/release/${{ env.PROJECT_NAME }}_${{ matrix.os }}_latest${{ matrix.extension }}
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: ${{ env.PROJECT_NAME }}-${{ env.VERSION }}-ubuntu-latest
path: ./release/ubuntu
- name: Download artifacts
uses: actions/download-artifact@v2
with:
name: ${{ env.PROJECT_NAME }}-${{ env.VERSION }}-macos-latest
path: ./release/macos
- name: Download artifacts
uses: actions/download-artifact@v2
with:
name: ${{ env.PROJECT_NAME }}-${{ env.VERSION }}-windows-latest
path: ./release/windows
- 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/ubuntu/${PROJECT_NAME}_ubuntu_latest $TARGET_DIR/${PROJECT_NAME}_ubuntu_latest
cp ./release/macos/${PROJECT_NAME}_macos_latest $TARGET_DIR/${PROJECT_NAME}_macos_latest
cp ./release/windows/${PROJECT_NAME}_windows_latest.exe $TARGET_DIR/${PROJECT_NAME}_windows_latest.exe
cp ./release/ubuntu/${PROJECT_NAME}_ubuntu_latest $TARGET_DIR/$PROJECT_NAME/$VERSION/${PROJECT_NAME}_ubuntu
cp ./release/macos/${PROJECT_NAME}_macos_latest $TARGET_DIR/$PROJECT_NAME/$VERSION/${PROJECT_NAME}_macos
cp ./release/windows/${PROJECT_NAME}_windows_latest.exe $TARGET_DIR/$PROJECT_NAME/$VERSION/${PROJECT_NAME}_windows.exe
- 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."