-
Notifications
You must be signed in to change notification settings - Fork 8
184 lines (157 loc) · 5.82 KB
/
calimero_node_macos.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
173
174
175
176
177
178
179
180
181
182
183
184
name: Build and Upload Meroctl for MacOS
on:
push:
branches:
- "**"
paths:
- Cargo.toml
- Cargo.lock
- "crates/**"
pull_request:
types: [closed]
jobs:
build:
runs-on: macos-latest
strategy:
matrix:
target: [x86_64-apple-darwin, aarch64-apple-darwin]
outputs:
artifact_path: ${{ steps.compress.outputs.artifact_path }}
target: ${{ matrix.target }}
version: ${{ steps.extract_version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
# Install Node.js (version 20) and pnpm
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '20'
- name: Install pnpm
run: npm install -g pnpm
# Install and build node-ui
- name: Install node-ui dependencies with pnpm
run: pnpm install --prefix ./node-ui
- name: Build node-ui
run: pnpm --filter ./node-ui run build
- name: Install rustup and Rust toolchain
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env
rustup toolchain install stable
rustup default stable
- name: Setup rust toolchain
run: rustup toolchain install stable --profile minimal
- name: Setup rust cache
uses: Swatinem/rust-cache@v2
with:
key: ${{ runner.os }}-meroctl-${{ matrix.target }}
- name: Install target for ${{ matrix.target }}
run: rustup target add ${{ matrix.target }}
- name: Build meroctl binary
run: cargo build -p meroctl --release --target ${{ matrix.target }}
- name: Extract version
id: extract_version
run: |
VERSION=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.name == "meroctl") | .version')
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Compress artifact using gzip
id: compress
run: |
mkdir -p release
cp target/${{ matrix.target }}/release/meroctl release/
tar -czf meroctl_${{ matrix.target }}.tar.gz -C release meroctl
echo "artifact_path=meroctl_${{ matrix.target }}.tar.gz" >> $GITHUB_OUTPUT
echo "target=${{ matrix.target }}" >> $GITHUB_OUTPUT
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: meroctl_${{ matrix.target }}.tar.gz
path: meroctl_${{ matrix.target }}.tar.gz
retention-days: 2
upload_branch_artifact:
runs-on: ubuntu-latest
needs: build
strategy:
matrix:
target: [x86_64-apple-darwin, aarch64-apple-darwin]
if: ${{ github.ref != 'refs/heads/master' }}
steps:
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: meroctl_${{ matrix.target }}.tar.gz
- name: Sanitize ref name
id: sanitize
run: |
sanitized_ref_name=$(echo "${GITHUB_REF_NAME}" | sed 's/[^a-zA-Z0-9_-]/-/g; s/^-*//; s/-*$//')
echo "sanitized_ref_name=${sanitized_ref_name}" >> $GITHUB_OUTPUT
create_release:
runs-on: ubuntu-latest
needs: build
strategy:
matrix:
target: [x86_64-apple-darwin, aarch64-apple-darwin]
if: ${{ github.ref == 'refs/heads/master' || (github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'master') }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Check if release exists
id: check_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION=${{ needs.build.outputs.version }}
if gh release view "v$VERSION" >/dev/null 2>&1; then
echo "release_exists=true" >> $GITHUB_ENV
else
echo "release_exists=false" >> $GITHUB_ENV
fi
- name: Create release if it does not exist
if: env.release_exists == 'false'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION=${{ needs.build.outputs.version }}
gh release create "v$VERSION" --title "Release v$VERSION" --notes "Release for version $VERSION"
upload_release_artifact:
runs-on: ubuntu-latest
needs: [build, create_release]
strategy:
matrix:
target: [x86_64-apple-darwin, aarch64-apple-darwin]
if: ${{ github.ref == 'refs/heads/master' || (github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'master') }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download Artifact
uses: actions/download-artifact@v4
with:
name: meroctl_${{ matrix.target }}.tar.gz
- name: Check if artifact exists in release
id: check_artifact
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION=${{ needs.build.outputs.version }}
TARGET=${{ matrix.target }}
ARTIFACT_NAME="meroctl_${TARGET}.tar.gz"
ASSET_ID=$(gh api \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
/repos/${{ github.repository }}/releases/tags/v$VERSION \
| jq -r ".assets[] | select(.name == \"$ARTIFACT_NAME\") | .id")
echo "ASSET_ID=$ASSET_ID"
if [[ -n "$ASSET_ID" ]]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Upload artifact to release
if: steps.check_artifact.outputs.exists == 'false'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
VERSION=${{ needs.build.outputs.version }}
TARGET=${{ matrix.target }}
gh release upload "v$VERSION" meroctl_${TARGET}.tar.gz