-
Notifications
You must be signed in to change notification settings - Fork 0
119 lines (98 loc) · 4.27 KB
/
on_release_attach_artifacts.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
name: Attach artifacts on release
on:
workflow_dispatch:
release:
types: [published]
pull_request:
branches: ["main", "master"]
permissions:
contents: write
jobs:
build:
strategy:
matrix:
runs-on: [ubuntu-22.04, macos-12]
runs-on: ${{ matrix.runs-on }}
name: Build
steps:
- name: Set up Go 1.20.7
uses: actions/setup-go@v3
with:
go-version: 1.20.7
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v3
with:
fetch-depth: "0"
- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable
- name: Set environment variables
run: |
GOOS=$(go env GOOS)
GOARCH=$(go env GOARCH)
GOPATH=$(go env GOPATH)
BUILD_DIR=${GITHUB_WORKSPACE}/build
ARCHIVE="mx_scenario_go""_""$GOOS""_""$GOARCH"".zip"
VM_GO_VERSION=$(cat go.mod | grep mx-chain-vm-go | sort -n | tail -n -1| awk -F '/' '{print$3}'| sed 's/ /@/g')
VM_GO_DIR=${GOPATH}/pkg/mod/github.com/multiversx/${VM_GO_VERSION}
echo "GOOS=${GOOS}" >> $GITHUB_ENV
echo "GOARCH=${GOARCH}" >> $GITHUB_ENV
echo "GOPATH=${GOPATH}" >> $GITHUB_ENV
echo "BUILD_DIR=${BUILD_DIR}" >> $GITHUB_ENV
echo "ARCHIVE=${ARCHIVE}" >> $GITHUB_ENV
echo "VM_GO_DIR=${VM_GO_DIR}" >> $GITHUB_ENV
- name: Build
run: |
mkdir -p ${BUILD_DIR}
cd ${GITHUB_WORKSPACE}/cmd/mx-scenario-go
go build -o "${BUILD_DIR}/mx-scenario-go"
- name: Copy & link Wasmer libraries
run: |
if [[ "$GOOS" == linux && "$GOARCH" == amd64 ]]; then
cp --verbose --no-preserve=mode,ownership ${VM_GO_DIR}/wasmer2/libvmexeccapi.so ${BUILD_DIR}/libvmexeccapi.so
cp --verbose --no-preserve=mode,ownership ${VM_GO_DIR}/wasmer/libwasmer_linux_amd64.so ${BUILD_DIR}/libwasmer_linux_amd64.so
patchelf --replace-needed libvmexeccapi.so libvmexeccapi.so ${BUILD_DIR}/mx-scenario-go
patchelf --replace-needed libwasmer_linux_amd64.so libwasmer_linux_amd64.so ${BUILD_DIR}/mx-scenario-go
patchelf --set-rpath "\$ORIGIN" ${BUILD_DIR}/mx-scenario-go
ldd ${BUILD_DIR}/mx-scenario-go
fi
if [[ "$GOOS" == darwin && "$GOARCH" == amd64 ]]; then
cp -v ${VM_GO_DIR}/wasmer2/libvmexeccapi.dylib ${BUILD_DIR}/libvmexeccapi.dylib
cp -v ${VM_GO_DIR}/wasmer/libwasmer_darwin_amd64.dylib ${BUILD_DIR}/libwasmer_darwin_amd64.dylib
install_name_tool -id "@rpath/libvmexeccapi.dylib" ${BUILD_DIR}/libvmexeccapi.dylib
install_name_tool -id "@rpath/libwasmer_darwin_amd64.dylib" ${BUILD_DIR}/libwasmer_darwin_amd64.dylib
install_name_tool -add_rpath "@loader_path" ${BUILD_DIR}/mx-scenario-go
otool -L ${BUILD_DIR}/mx-scenario-go
fi
- name: Smoke test
run: |
# Remove all downloaded Go packages, so that we can test the binary's independence from them (think of Wasmer libraries).
sudo rm -rf ${GOPATH}/pkg/mod
# Test the binary in different current directories.
cd ${BUILD_DIR} && ./mx-scenario-go --version
cd ${GITHUB_WORKSPACE} && ${BUILD_DIR}/mx-scenario-go --version
cd / && ${BUILD_DIR}/mx-scenario-go --version
- name: Package build output
run: |
sudo chown -R $USER: ${BUILD_DIR}
chmod -R 755 ${BUILD_DIR}
ls -al ${BUILD_DIR}
zip -r -j ${ARCHIVE} ${BUILD_DIR}
- name: Save artifacts
uses: actions/upload-artifact@v3
with:
name: build-output
path: ${{ env.ARCHIVE }}
if-no-files-found: error
- name: Upload artifacts to release
if: ${{ github.event_name == 'release' }}
run: |
gh release upload ${{ github.event.release.tag_name }} ${{ env.ARCHIVE}}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}