generated from metaplex-foundation/solana-project-template
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ad7167
commit f5bdcfa
Showing
1 changed file
with
177 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
name: Deploy Program | ||
|
||
on: | ||
workflow_dispatch: | ||
inputs: | ||
program: | ||
description: Program | ||
required: true | ||
default: bubblegum | ||
type: choice | ||
options: | ||
- bubblegum | ||
cluster: | ||
description: Cluster environment | ||
required: true | ||
default: devnet | ||
type: choice | ||
options: | ||
- devnet | ||
- mainnet-beta | ||
publish_crate: | ||
description: Release cargo crate | ||
required: true | ||
type: boolean | ||
default: false | ||
bump: | ||
description: Version bump | ||
required: true | ||
default: patch | ||
type: choice | ||
options: | ||
- patch | ||
- minor | ||
- major | ||
|
||
env: | ||
CACHE: true | ||
|
||
jobs: | ||
build_programs: | ||
name: Programs | ||
uses: ./.github/workflows/build-programs.yml | ||
secrets: inherit | ||
|
||
test_js: | ||
name: JS client | ||
needs: build_programs | ||
uses: ./.github/workflows/test-js.yml | ||
secrets: inherit | ||
|
||
deploy_program: | ||
name: Program / Deploy | ||
runs-on: ubuntu-latest | ||
needs: test_js | ||
permissions: | ||
contents: write | ||
steps: | ||
- name: Git checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Load environment variables | ||
run: cat .github/.env >> $GITHUB_ENV | ||
|
||
- name: Install Rust | ||
uses: metaplex-foundation/actions/install-rust@v1 | ||
with: | ||
toolchain: ${{ env.RUST_VERSION }} | ||
|
||
- name: Install Solana | ||
uses: metaplex-foundation/actions/install-solana@v1 | ||
with: | ||
version: ${{ env.SOLANA_VERSION }} | ||
cache: ${{ env.CACHE }} | ||
|
||
- name: Install Anchor CLI | ||
uses: metaplex-foundation/actions/install-anchor-cli@v1 | ||
with: | ||
version: ${{ env.ANCHOR_VERSION }} | ||
cache: ${{ env.CACHE }} | ||
|
||
- name: Install cargo-release | ||
uses: metaplex-foundation/actions/install-cargo-release@v1 | ||
if: github.event.inputs.publish_crate == 'true' | ||
with: | ||
cache: ${{ env.CACHE }} | ||
|
||
- name: Set RPC | ||
run: | | ||
if [ "${{ inputs.cluster }}" == "devnet" ]; then | ||
echo RPC=${{ secrets.DEVNET_RPC }} >> $GITHUB_ENV | ||
else | ||
echo RPC=${{ secrets.MAINNET_RPC }} >> $GITHUB_ENV | ||
fi | ||
- name: Identify Program | ||
run: | | ||
if [ "${{ inputs.program }}" == "bubblegum" ]; then | ||
echo ${{ secrets.BUBBLEGUM_DEPLOY_KEY }} > ./deploy-key.json | ||
echo ${{ secrets.BUBBLEGUM_ID }} > ./program-id.json | ||
echo PROGRAM_NAME="mpl_bubblegum" >> $GITHUB_ENV | ||
fi | ||
- name: Bump Program Version | ||
run: | | ||
IDL_NAME=`echo "${{ inputs.program }}" | tr - _` | ||
VERSION=`jq '.version' ./idls/${IDL_NAME}.json | sed 's/"//g'` | ||
MAJOR=`echo ${VERSION} | cut -d. -f1` | ||
MINOR=`echo ${VERSION} | cut -d. -f2` | ||
PATCH=`echo ${VERSION} | cut -d. -f3` | ||
if [ "${{ inputs.bump }}" == "major" ]; then | ||
MAJOR=$((MAJOR + 1)) | ||
MINOR=0 | ||
PATCH=0 | ||
elif [ "${{ inputs.bump }}" == "minor" ]; then | ||
MINOR=$((MINOR + 1)) | ||
PATCH=0 | ||
else | ||
PATCH=$((PATCH + 1)) | ||
fi | ||
PROGRAM_VERSION="${MAJOR}.${MINOR}.${PATCH}" | ||
cp ./idls/${IDL_NAME}.json ./idls/${IDL_NAME}-previous.json | ||
jq ".version = \"${PROGRAM_VERSION}\"" ./idls/${IDL_NAME}-previous.json > ./idls/${IDL_NAME}.json | ||
rm ./idls/${IDL_NAME}-previous.json | ||
echo PROGRAM_VERSION="${PROGRAM_VERSION}" >> $GITHUB_ENV | ||
- name: Download Program Builds | ||
uses: actions/download-artifact@v3 | ||
with: | ||
name: program-builds | ||
|
||
- name: Deploy Program | ||
run: | | ||
echo "Deploying ${{ inputs.program }} to ${{ inputs.cluster }}" | ||
solana -v program deploy ./programs/.bin/${{ env.PROGRAM_NAME }}.so \ | ||
-u ${{ env.RPC }} \ | ||
--program-id ./program-id.json \ | ||
-k ./deploy-key.json | ||
- name: Upgrade IDL | ||
working-directory: ./programs/${{ inputs.program }} | ||
run: | | ||
jq 'del(.metadata?) | del(.. | .docs?)' ../../idls/`echo "${{ inputs.program }}" | tr - _`.json > ./idl.json | ||
anchor idl upgrade -f ./idl.json \ | ||
--provider.cluster ${{ env.RPC }} \ | ||
--provider.wallet ../../deploy-key.json \ | ||
`solana address -k ../../program-id.json` | ||
rm ../../deploy-key.json | ||
rm ../../program-id.json | ||
rm ./idl.json | ||
- name: Publish crate | ||
working-directory: ./programs/${{ inputs.program }}/program | ||
if: github.event.inputs.publish_crate == 'true' && github.event.inputs.cluster == 'mainnet-beta' | ||
run: | | ||
git stash | ||
git config user.name "${{ env.COMMIT_USER_NAME }}" | ||
git config user.email "${{ env.COMMIT_USER_EMAIL }}" | ||
cargo login ${{ secrets.CRATES_TOKEN }} | ||
cargo release ${{ inputs.bump }} --no-confirm --no-push --no-tag --execute | ||
git reset --soft HEAD~1 | ||
git stash pop | ||
- name: Commit and tag new version | ||
uses: stefanzweifel/git-auto-commit-action@v4 | ||
if: github.event.inputs.publish_crate == 'true' && github.event.inputs.cluster == 'mainnet-beta' | ||
with: | ||
commit_message: Deploy mpl-${{ inputs.program }} program v${{ env.PROGRAM_VERSION }} | ||
tagging_message: mpl-${{ inputs.program }}@v${{ env.PROGRAM_VERSION }} |