1+ name : Build Contracts
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ contractName :
7+ description : ' Enter Contract Name'
8+ required : true
9+ default : ' RandomContract'
10+ type : choice
11+ options :
12+ - ' RandomContract'
13+ version :
14+ description : ' Enter Contract Version'
15+ required : true
16+ default : ' 1.0.0'
17+ netsdk :
18+ description : ' Select .NET SDK Version'
19+ required : true
20+ default : ' 8.0'
21+ type : choice
22+ options :
23+ - ' 8.0'
24+
25+ env :
26+ DOTNET_INSTALL_DIR : " ./.dotnet"
27+
28+ concurrency :
29+ group : workflow-${{ github.ref }}
30+ cancel-in-progress : true
31+
32+ jobs :
33+ prepare-matrix :
34+ runs-on : ubuntu-latest
35+ outputs :
36+ matrix : ${{ steps.set-matrix.outputs.matrix }}
37+ steps :
38+ - name : Generate Dynamic Matrix
39+ id : set-matrix
40+ run : |
41+ echo "[\"${{ github.event.inputs.contractName }}\"]" > matrix.json
42+ echo "matrix=$(cat matrix.json)" >> $GITHUB_OUTPUT
43+
44+ build-contract :
45+ runs-on : ubuntu-latest
46+ needs : prepare-matrix
47+ strategy :
48+ matrix :
49+ contractName : ${{ fromJson(needs.prepare-matrix.outputs.matrix) }}
50+
51+ steps :
52+ - name : Debug Matrix Inputs
53+ run : |
54+ echo "The contract name from matrix is: ${{ matrix.contractName }}"
55+
56+ - name : Checkout Code
57+ uses : actions/checkout@v4
58+
59+ - name : Setup .NET
60+ uses : actions/setup-dotnet@v3
61+ with :
62+ dotnet-version : ' 8.0.x'
63+
64+ - name : Set Variables
65+ run : |
66+ VERSION="${{ github.event.inputs.version }}"
67+ NETSDK="${{ github.event.inputs.netsdk }}"
68+ HOME_DIR="${{ github.workspace }}/contracts_auto_build/${{ matrix.contractName }}"
69+
70+ case "${NETSDK}" in
71+ "9.0")
72+ IMAGE_NAME="aelf/build-contracts:dotnet-sdk-9.0-noble-amd64"
73+ ;;
74+ "8.0")
75+ IMAGE_NAME="aelf/build-contracts:dotnet-sdk-8.0.204-amd64"
76+ ;;
77+ *)
78+ echo "Error: Unsupported .NET SDK version selected."
79+ exit 1
80+ ;;
81+ esac
82+
83+ echo "VERSION=${VERSION}" >> $GITHUB_ENV
84+ echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_ENV
85+ echo "HOME_DIR=${HOME_DIR}" >> $GITHUB_ENV
86+
87+ - name : Build Selected Contract(s)
88+ run : |
89+ # Check if HOME_DIR is set
90+ if [ -z "${{ env.HOME_DIR }}"]; then
91+ echo "HOME_DIR environment variable is not set"
92+ exit 1
93+ fi
94+
95+ # Create build directory if it doesn't exist
96+ if [ ! -d "${{ env.HOME_DIR }}/build" ]; then
97+ mkdir -p "${{ env.HOME_DIR }}/build"
98+ fi
99+
100+ # Create contracts directory if it doesn't exist
101+ if [ ! -d "${{ env.HOME_DIR }}/contracts" ]; then
102+ mkdir -p "${{ env.HOME_DIR }}/contracts"
103+ fi
104+
105+ echo "Copying contracts for ${{ env.HOME_DIR }}/contracts/"
106+
107+ for item in *; do
108+ if [ "$item" != "contracts_auto_build" ] && [ "$item" != "$(basename "${HOME_DIR}/contracts/")" ]; then
109+ cp -r "$item" "${HOME_DIR}/contracts/"
110+ fi
111+ done
112+
113+ echo "Copying build.sh to ${{ env.HOME_DIR }}/build.sh"
114+
115+ if [ -f "build.sh" ]; then
116+ cp build.sh "${{ env.HOME_DIR }}/build.sh"
117+ else
118+ echo "build.sh not found in the current directory."
119+ exit 1
120+ fi
121+
122+ - name : Build Contract
123+ run : |
124+ echo "Building contract: ${{ matrix.contractName }}"
125+ cd ${{ env.HOME_DIR }}
126+ docker run --rm --name build-contracts \
127+ -e USER=root \
128+ -v ${{ env.HOME_DIR }}/contracts:/opt/contracts \
129+ -v ${{ env.HOME_DIR }}/build:/opt/build \
130+ -v ${{ env.HOME_DIR }}/build.sh:/opt/build.sh \
131+ ${{ env.IMAGE_NAME }} /bin/bash -x /opt/build.sh \
132+ ${{ matrix.contractName }} ${{ env.VERSION }}
133+
134+ - name : Archive Build Contract
135+ run : |
136+ cd ${{ env.HOME_DIR }}
137+ tar cfz ${{ matrix.contractName }}.${{ env.VERSION }}.tgz -C build .
138+
139+ - name : Upload build contract
140+ uses : actions/upload-artifact@v4
141+ with :
142+ name : ${{ matrix.contractName }}-contract
143+ path : ${{ env.HOME_DIR }}/${{ matrix.contractName }}.${{ env.VERSION }}.tgz
144+ retention-days : 7
0 commit comments