-
Notifications
You must be signed in to change notification settings - Fork 7
237 lines (205 loc) · 7.99 KB
/
release.yml
File metadata and controls
237 lines (205 loc) · 7.99 KB
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
name: Build and Release Contract
on:
workflow_call:
inputs:
relative_path:
description: 'Relative path to the working directory'
type: string
required: false
make_target:
description: 'Make target for the contract'
type: string
required: false
package:
description: 'Package to build'
type: string
required: false
release_name:
description: 'Name for the release'
required: true
type: string
release_description:
description: 'Description for the release'
required: false
type: string
home_domain:
description: 'Home domain'
required: false
type: string
secrets:
release_token:
description: 'Github token'
required: true
permissions:
id-token: write
contents: write
attestations: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Set working directory
run: |
RANDOM_DIR=$(openssl rand -hex 8)
WORK_DIR="${{ github.workspace }}/$RANDOM_DIR"
mkdir -p "$WORK_DIR"
echo "WORK_DIR=$WORK_DIR" >> $GITHUB_ENV
echo "Using working directory: $WORK_DIR"
- name: Checkout code
uses: actions/checkout@v4
with:
path: ${{ env.WORK_DIR }}
- name: Set relative path
run: |
# Set relative path after checking out the code
if [ "${{ inputs.relative_path }}" ]; then
WORK_DIR="$WORK_DIR/${{ inputs.relative_path }}"
echo "WORK_DIR=$WORK_DIR" >> $GITHUB_ENV
echo "Using relative path: $WORK_DIR"
fi
- name: Run Make (if applicable)
if: inputs.make_target != ''
working-directory: ${{ env.WORK_DIR }}
run: |
make ${{ inputs.make_target }}
- name: Update Rust and Add wasm32 Target
working-directory: ${{ env.WORK_DIR }}
run: |
rustup update
rustup target add wasm32v1-none
- name: Print versions
run: |
rustc --version
cargo --version
- name: Install jq
run: sudo apt-get update && sudo apt-get install -y jq
- name: Get Cargo.toml metadata
working-directory: ${{ env.WORK_DIR }}
run: |
if [ ! -f "Cargo.toml" ]; then
echo "Cargo.toml does not exist"
exit 1
fi
CARGO_METADATA=$(cargo metadata --format-version=1 --no-deps)
echo "CARGO_METADATA=$CARGO_METADATA" >> $GITHUB_ENV
- name: Set output directory path
run: |
RANDOM_DIR=$(openssl rand -hex 8)
OUTPUT="$WORK_DIR/$RANDOM_DIR"
echo "OUTPUT=$OUTPUT" >> $GITHUB_ENV
- name: Build contract
uses: stellar/stellar-cli@v25.1.0
with:
version: '25.1.0'
- run: |
# Navigate to the working directory
cd ${WORK_DIR}
# Build command arguments
COMMAND_ARGS="--out-dir ${OUTPUT} --meta source_repo=github:${{ github.repository }}"
if [ "${{ inputs.package }}" ]; then
COMMAND_ARGS="--package ${{ inputs.package }} $COMMAND_ARGS"
PACKAGE_NAME=${{ inputs.package }}
else
PACKAGE_NAME=$(grep -m1 '^name =' Cargo.toml | cut -d '"' -f2)
fi
if [ "${{ inputs.home_domain }}" ]; then
COMMAND_ARGS="$COMMAND_ARGS --meta home_domain=${{ inputs.home_domain }}"
fi
# Build the contract
stellar contract build --optimize $COMMAND_ARGS
# Get the package version
PACKAGE_VERSION=$(echo "$CARGO_METADATA" | jq '.packages[] | select(.name == "'"${PACKAGE_NAME}"'") | .version' | sed -e 's/"//g')
if [ -z "$PACKAGE_VERSION" ]; then
echo "ERROR: Failed to get the package version"
exit 1
fi
# Build the wasm file name
WASM_FILE_NAME="${PACKAGE_NAME}_v${PACKAGE_VERSION}.wasm"
# Navigate to the output directory
cd ${OUTPUT}
# Find the .wasm file and copy it as unoptimized.wasm for hash calculation
find ${OUTPUT} -name "*.wasm" -exec cp {} ${WASM_FILE_NAME} \;
# Calculate the hash of the wasm file
WASM_HASH=$(sha256sum $WASM_FILE_NAME | cut -d ' ' -f 1)
# Set environment variables
echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_ENV
echo "WASM_FILE_NAME=$WASM_FILE_NAME" >> $GITHUB_ENV
echo "WASM_HASH=$WASM_HASH" >> $GITHUB_ENV
echo "PACKAGE_NAME=$PACKAGE_NAME" >> $GITHUB_ENV
echo "BUILD_INFO=$BUILD_INFO" >> $GITHUB_ENV
- name: Build release name
run: |
CLI_VERSION=$(stellar --version | grep -oP 'stellar \K\S+')
if [ -n "${{ inputs.relative_path }}" ]; then
relative_path=$(echo "_${{ inputs.relative_path }}" | sed 's/\W\+/_/g')
fi
# Check if the release_name input is equal to PACKAGE_VERSION
if [ "${{ inputs.release_name }}" != "${PACKAGE_VERSION}" ] && [ "${{ inputs.release_name }}" != "v${PACKAGE_VERSION}" ]; then
pkg_version="_pkg${PACKAGE_VERSION}"
else
pkg_version=""
fi
TAG_NAME="${{ inputs.release_name }}${relative_path}_${PACKAGE_NAME}${pkg_version}_cli${CLI_VERSION}"
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_ENV
- name: Create release
working-directory: ${{ env.OUTPUT }}
env:
GH_TOKEN: ${{ secrets.release_token }}
run: |
gh release create "${{ env.TAG_NAME }}" "${{ env.OUTPUT }}/${{ env.WASM_FILE_NAME }}" \
--title "${{ env.TAG_NAME }}" \
--notes "${{ inputs.release_description }}"
shell: bash
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '14'
- name: Build output
run: |
JSON_OUTPUT=$(node -e "console.log(JSON.stringify({
wasm: process.env.WASM,
hash: process.env.HASH,
relPath: (process.env.REL_PATH || undefined),
package: (process.env.PACKAGE || undefined),
make: (process.env.MAKE || undefined)
}))")
echo "WASM_OUTPUT='$JSON_OUTPUT'" >> $GITHUB_ENV
env:
REL_PATH: ${{ inputs.relative_path }}
PACKAGE: ${{ inputs.package }}
MAKE: ${{ inputs.make_target }}
HASH: ${{ env.WASM_HASH }}
WASM: ${{ env.WASM_FILE_NAME }}
- name: Output WASM ${{ env.WASM_OUTPUT }}
run: echo ${{ env.WASM_OUTPUT }}
- name: Send release info
run: |
JSON_OBJECT=$(node -e "console.log(JSON.stringify({
repository: process.env.REPOSITORY,
commitHash: process.env.COMMIT_HASH,
jobId: process.env.JOB_ID,
runId: process.env.RUN_ID,
contractHash: process.env.CONTRACT_HASH,
relativePath: process.env.RELATIVE_PATH || undefined,
packageName: process.env.PACKAGE_NAME || undefined,
makeTarget: process.env.MAKE_TARGET || undefined
}))")
echo "JSON to send: $JSON_OBJECT"
curl -X POST "https://api.stellar.expert/explorer/public/contract-validation/match" \
-H "Content-Type: application/json" \
-d "$JSON_OBJECT" \
--max-time 15
env:
REPOSITORY: ${{ github.server_url }}/${{ github.repository }}
COMMIT_HASH: ${{ github.sha }}
JOB_ID: ${{ github.job }}
RUN_ID: ${{ github.run_id }}
CONTRACT_HASH: ${{ env.WASM_HASH }}
RELATIVE_PATH: ${{ inputs.relative_path }}
PACKAGE_NAME: ${{ inputs.package }}
MAKE_TARGET: ${{ inputs.make_target }}
- name: Attest
uses: actions/attest-build-provenance@v1
with:
subject-path: '${{ env.OUTPUT }}/${{ env.WASM_FILE_NAME }}'
subject-name: '${{ env.WASM_FILE_NAME }}'