Skip to content

Version Program

Version Program #6

name: Version Program
on:
workflow_dispatch:
inputs:
program:
description: Program
required: true
default: asset
type: choice
options:
- asset
- bridge
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_programs:
name: Programs
needs: build_programs
uses: ./.github/workflows/test-programs.yml
secrets: inherit
with:
program_matrix: '["${{ inputs.program }}"]'
test_js:
name: JS client
needs: build_programs
uses: ./.github/workflows/test-js-client.yml
secrets: inherit
with:
client_matrix: '["${{ inputs.program }}"]'
test_rust:
name: Rust client
needs: build_programs
uses: ./.github/workflows/test-rust-client.yml
secrets: inherit
with:
client_matrix: '["${{ inputs.program }}"]'
version_program:
name: Program / Version
runs-on: ubuntu-latest
needs: [test_programs, test_js, test_rust]
permissions:
contents: write
steps:
- name: Git checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.SERVICE_TOKEN }}
- name: Load environment variables
run: cat .github/.env >> $GITHUB_ENV
- name: Install Rust
uses: nifty-oss/actions/install-rust@v1
with:
toolchain: ${{ env.RUST_VERSION }}
- uses: nifty-oss/actions/install-cargo-release@v1
with:
cache: true
- name: Bump Program Version
run: |
IDL_NAME="`echo "${{ inputs.program }}_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
truncate -s -1 ./idls/${IDL_NAME}.json
rm ./idls/${IDL_NAME}-previous.json
echo PROGRAM_VERSION="${PROGRAM_VERSION}" >> $GITHUB_ENV
- name: Version Program
working-directory: ./programs
run: |
PROGRAM_DIR="${{ inputs.program }}"
if [ "${PROGRAM_DIR}" == "asset" ]; then
PROGRAM_DIR="${{ inputs.program }}/program"
fi
cd $PROGRAM_DIR
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 ${{ env.PROGRAM_VERSION }} --no-confirm --no-push --no-tag --no-publish --execute
git reset --soft HEAD~1
git stash pop
- name: Commit and tag new version
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "chore: ${{ inputs.program }} program version ${{ env.PROGRAM_VERSION }}"
tagging_message: ${{ inputs.program }}_program@v${{ env.PROGRAM_VERSION }}