-
Notifications
You must be signed in to change notification settings - Fork 3
182 lines (158 loc) · 6.71 KB
/
release.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
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 directory names and paths
run: |
build_dir_name="build_"$(openssl rand -base64 8 | tr -d '/+=' | head -c 8)
echo "BUILD_DIR_NAME=$build_dir_name" >> $GITHUB_ENV
echo "BUILD_DIR_PATH=${{ github.workspace }}/$build_dir_name" >> $GITHUB_ENV
- name: Verify that checkout directory doesn't exist
run: |
if [[ -d ${{ env.BUILD_DIR_PATH }} ]]; then
echo "Directory ${{ env.BUILD_DIR_PATH }} already exists"
exit 1
fi
- name: Checkout code
uses: actions/checkout@v4
with:
path: ${{ env.BUILD_DIR_NAME }}
- name: Run docker container
working-directory: ${{ env.BUILD_DIR_PATH }}
run: docker run --rm -e RELATIVE_PATH=${{ inputs.relative_path }} -e MAKE_TARGET=${{ inputs.make_target }} -e PACKAGE=${{ inputs.package }} -e REPO=github:${{github.event.repository.full_name}} -e HOME_DOMAIN=${{inputs.home_domain}} -v "${{ env.BUILD_DIR_PATH }}:/inspector/home" ghcr.io/stellar-expert/soroban-build-workflow:v22.0.1
- name: Get compilation info
working-directory: ${{ env.BUILD_DIR_PATH }}
run: |
# Compilation info JSON file
JSON_FILE="${BUILD_DIR_PATH}/compilation_workflow_release/compilation_info.json"
# Check if the file exists
if [ -f "$JSON_FILE" ]; then
# Read the JSON file
json=$(cat "$JSON_FILE")
# Parse values from JSON using native Bash commands
PACKAGE_NAME=$(echo "$json" | grep -oP '"packageName": "\K[^"]+')
PACKAGE_VERSION=$(echo "$json" | grep -oP '"packageVersion": "\K[^"]+')
CLI_VERSION=$(echo "$json" | grep -oP '"cliVersion": "\K[^"]+')
WASM_FILE_NAME=$(echo "$json" | grep -oP '"wasmFileName": "\K[^"]+')
WASM_HASH=$(echo "$json" | grep -oP '"wasmHash": "\K[^"]+')
# Set environment variables using 'echo' to be picked up by GitHub Actions
echo "PACKAGE_NAME=$PACKAGE_NAME" >> $GITHUB_ENV
echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_ENV
echo "CLI_VERSION=$CLI_VERSION" >> $GITHUB_ENV
echo "WASM_FILE_NAME=$WASM_FILE_NAME" >> $GITHUB_ENV
echo "WASM_HASH=$WASM_HASH" >> $GITHUB_ENV
else
echo "The JSON file $JSON_FILE does not exist."
exit 1
fi
- name: Build release name
run: |
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 }}" != "${{ env.PACKAGE_VERSION }}" ] && [ "${{ inputs.release_name }}" != "v${{ env.PACKAGE_VERSION }}" ]; then
pkg_version="_pkg${{ env.PACKAGE_VERSION }}"
else
pkg_version=""
fi
tag_name="${{ inputs.release_name }}${relative_path}_${{ env.PACKAGE_NAME }}${pkg_version}_cli${{ env.CLI_VERSION }}"
echo "TAG_NAME=$tag_name" >> $GITHUB_ENV
- name: Create release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ env.TAG_NAME }}
draft: false
prerelease: false
body: ${{ inputs.release_description }}
files: '${{ env.BUILD_DIR_PATH }}/compilation_workflow_release/${{ env.WASM_FILE_NAME }}'
token: ${{ secrets.release_token }}
- 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.BUILD_DIR_PATH }}/compilation_workflow_release/${{ env.WASM_FILE_NAME }}'
subject-name: '${{ env.WASM_FILE_NAME }}'