1
+ name : " Program Upgrade"
2
+ description : " Upgrades or deploys a Solana program"
3
+ inputs :
4
+ program-id :
5
+ description : " Program ID to upgrade"
6
+ required : true
7
+ program :
8
+ description : " Program name"
9
+ required : true
10
+ buffer :
11
+ description : " Buffer address"
12
+ required : true
13
+ rpc-url :
14
+ description : " Solana RPC URL"
15
+ required : true
16
+ keypair :
17
+ description : " Deployer keypair"
18
+ required : true
19
+ program-keypair :
20
+ description : " Program address keypair for initial deployment"
21
+ required : true
22
+
23
+ runs :
24
+ using : " composite"
25
+ steps :
26
+ - uses : ./.github/actions/setup/
27
+ - uses : ./.github/actions/setup-solana/
28
+
29
+ - name : Write keypairs
30
+ shell : bash
31
+ run : |
32
+ echo "$DEPLOY_KEYPAIR" > ./deploy-keypair.json && chmod 600 ./deploy-keypair.json
33
+ echo "$PROGRAM_KEYPAIR" > ./program-keypair.json && chmod 600 ./program-keypair.json
34
+ env :
35
+ DEPLOY_KEYPAIR : ${{ inputs.keypair }}
36
+ PROGRAM_KEYPAIR : ${{ inputs.program-keypair }}
37
+
38
+ - name : Check if program exists
39
+ id : check-program
40
+ shell : bash
41
+ run : |
42
+ if solana program show ${{ inputs.program-id }} --url ${{ inputs.rpc-url }} 2>&1 | grep -q "Data Length:"; then
43
+ echo "exists=true" >> $GITHUB_OUTPUT
44
+ else
45
+ echo "exists=false" >> $GITHUB_OUTPUT
46
+ fi
47
+
48
+ - name : Deploy new program
49
+ if : steps.check-program.outputs.exists == 'false'
50
+ uses : nick-invision/retry@v2
51
+ with :
52
+ timeout_minutes : 10
53
+ max_attempts : 3
54
+ command : |
55
+ solana program deploy \
56
+ --url ${{ inputs.rpc-url }} \
57
+ --keypair ./deploy-keypair.json \
58
+ --program-id ./program-keypair.json \
59
+ --max-sign-attempts 50 \
60
+ --with-compute-unit-price 100000 \
61
+ --use-rpc \
62
+ ./target/deploy/${{ inputs.program }}.so
63
+
64
+ - name : Upgrade existing program
65
+ if : steps.check-program.outputs.exists == 'true'
66
+ uses : nick-invision/retry@v2
67
+ with :
68
+ timeout_minutes : 10
69
+ max_attempts : 3
70
+ command : |
71
+ echo "Debug: Buffer value is '${{ inputs.buffer }}'"
72
+ if [ -z "${{ inputs.buffer }}" ]; then
73
+ echo "Error: No buffer provided"
74
+ exit 1
75
+ fi
76
+
77
+ # Get current and new program sizes
78
+ CURRENT_SIZE=$(solana program show "${{ inputs.program-id }}" -u "${{ inputs.rpc-url }}" | grep "Data Length:" | cut -d ":" -f2 | cut -d " " -f2)
79
+ NEW_SIZE=$(wc -c < "./target/deploy/${{ inputs.program }}.so")
80
+ echo "Current program size: $CURRENT_SIZE bytes"
81
+ echo "New program size: $NEW_SIZE bytes"
82
+
83
+ # Extend program if needed
84
+ if [ $NEW_SIZE -gt $CURRENT_SIZE ]; then
85
+ echo "Program needs to be extended"
86
+ solana program extend "${{ inputs.program-id }}" $((NEW_SIZE - CURRENT_SIZE)) -u "${{ inputs.rpc-url }}" -k ./deploy-keypair.json
87
+ echo "Program extended successfully"
88
+ fi
89
+
90
+ # Upgrade program
91
+ solana program upgrade "${{ inputs.buffer }}" "${{ inputs.program-id }}" -k ./deploy-keypair.json -u "${{ inputs.rpc-url }}"
92
+
93
+ env :
94
+ BUFFER : ${{ inputs.buffer }}
95
+ PROGRAM_ID : ${{ inputs.program-id }}
96
+ PROGRAM : ${{ inputs.program }}
97
+ RPC_URL : ${{ inputs.rpc-url }}
98
+
99
+ - name : Cleanup
100
+ if : always()
101
+ shell : bash
102
+ run : |
103
+ rm -f ./deploy-keypair.json
104
+ rm -f ./program-keypair.json
0 commit comments