1+ name : Build and Deploy Testnet
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ servicename :
7+ description : ' Select service to build and deploy'
8+ required : true
9+ default : ' AElfScanServer.Worker'
10+ type : choice
11+ options :
12+ - AElfScanServer.Worker
13+ - AElfScanServer.HttpApi.Host
14+ - AElfScanServer.Silo
15+ - AElfScanServer.AuthServer
16+ - AElfScanServer.DbMigrator
17+
18+ env :
19+ DOTNET_INSTALL_DIR : " ./.dotnet"
20+
21+ jobs :
22+ publish :
23+ runs-on : aelfscan-runner
24+ steps :
25+ - uses : actions/checkout@v4
26+ - uses : actions/setup-dotnet@v4
27+ with :
28+ dotnet-version : " 8.0"
29+ - run : dotnet publish src/${{ github.event.inputs.servicename}}/${{ github.event.inputs.servicename }}.csproj -o out/${{ github.event.inputs.servicename }}
30+ - name : Upload build artifacts
31+ uses : actions/upload-artifact@v4
32+ with :
33+ name : ${{ github.event.inputs.servicename }}
34+ path : out/${{ github.event.inputs.servicename }}
35+ retention-days : 1
36+
37+ build-and-push-image :
38+ needs : publish
39+ runs-on : aelfscan-runner
40+ permissions :
41+ contents : read
42+ outputs :
43+ short_sha : ${{ steps.vars.outputs.short_sha }}
44+ steps :
45+ - name : Checkout
46+ uses : actions/checkout@v4
47+ - name : Set short git commit SHA
48+ id : vars
49+ run : |
50+ calculatedSha=$(git rev-parse --short ${{ github.sha }})
51+ echo "short_sha=$calculatedSha" >> "$GITHUB_OUTPUT"
52+ - name : Download a single artifact
53+ uses : actions/download-artifact@v4
54+ with :
55+ name : ${{ github.event.inputs.servicename }}
56+ path : out/${{ github.event.inputs.servicename }}
57+ - name : Create image tag
58+ id : meta
59+ uses : docker/metadata-action@v5
60+ with :
61+ images : ${{ secrets.REPOSITORY_REGION }}-docker.pkg.dev/${{ secrets.PROJECT_ID }}/${{ secrets.REPOSITORY }}/${{ github.event.inputs.servicename }}
62+ tags : |
63+ type=sha
64+ - name : Set up Docker Buildx
65+ uses : docker/setup-buildx-action@v3
66+ - name : Build and push
67+ uses : docker/build-push-action@v5
68+ with :
69+ context : .
70+ push : true
71+ build-args : |
72+ servicename=${{ github.event.inputs.servicename }}
73+ platforms : linux/amd64
74+ tags : ${{ steps.meta.outputs.tags }}
75+ labels : ${{ steps.meta.outputs.labels }}
76+
77+ dispatch :
78+ runs-on : aelfscan-runner
79+ needs : build-and-push-image
80+ steps :
81+ - name : Map servicename to appName
82+ id : map-appname
83+ run : |
84+ case "${{ github.event.inputs.servicename }}" in
85+ "AElfScanServer.HttpApi.Host")
86+ appName="aelf-explorer-httpapi-host"
87+ ;;
88+ "AElfScanServer.Worker")
89+ appName="aelf-explorer-worker"
90+ ;;
91+ "AElfScanServer.Silo")
92+ appName="aelf-explorer-silo"
93+ ;;
94+ "AElfScanServer.AuthServer")
95+ appName="aelf-explorer-authserver"
96+ ;;
97+ "AElfScanServer.DbMigrator")
98+ appName="aelf-explorer-dbmigrator"
99+ ;;
100+ *)
101+ echo "Unknown service name: ${{ github.event.inputs.servicename }}"
102+ exit 1
103+ ;;
104+ esac
105+ echo "appName=$appName" >> "$GITHUB_ENV"
106+
107+ - name : Deploy
108+ uses : actions/github-script@v6
109+ with :
110+ github-token : ${{ secrets.TOK }}
111+ script : |
112+ await github.rest.actions.createWorkflowDispatch({
113+ owner: 'AelfScanProject',
114+ repo: 'devops',
115+ workflow_id: 'aelf-explorer-server-deploy.yaml',
116+ ref: 'main',
117+ inputs: {
118+ env: 'testnet',
119+ appName: process.env.appName,
120+ commit_sha: 'sha-${{ needs.build-and-push-image.outputs.short_sha }}',
121+ }
122+ })
0 commit comments