Skip to content

update

update #10

name: Validate Generated Code
on:
pull_request: # Typically, you'd want this on PRs to catch issues before merge
branches:
- main # Or your default branch, e.g., 'master'
push:
branches:
- main # Also useful on push to ensure main is always clean
workflow_dispatch: # Allows manual triggering from the GitHub UI
jobs:
validate_generated_code:
runs-on: ubuntu-latest # Or your preferred runner environment
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20' # Specify your Node.js version
# Removed 'cache: yarn' to prevent potential conflicts with Corepack's management.
- name: Enable Corepack and Install dependencies
run: |
corepack enable # This command enables Corepack to manage package managers like Yarn 2+
# Explicitly use 'corepack yarn' to ensure the correct Yarn version is invoked
corepack yarn install --frozen-lockfile # Use --frozen-lockfile for CI environments
- name: Set up Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable # Install the latest stable Rust toolchain
override: true
profile: minimal # Install minimal components for faster setup
- name: Update CA Certificates (Still useful for general system health)
run: |
sudo apt-get update
sudo apt-get install -y ca-certificates # Ensure the latest CA certificates are installed
- name: Install Solana CLI and Verify build-sbf
run: |
SOLANA_VERSION="1.18.15" # Specify a stable Solana CLI version. Adjust if your project needs a different one.
SOLANA_ARCH="x86_64-unknown-linux-gnu" # Architecture for ubuntu-latest runner
SOLANA_TARBALL="solana-release-${SOLANA_ARCH}.tar.bz2"
SOLANA_DOWNLOAD_URL="https://github.com/solana-labs/solana/releases/download/v${SOLANA_VERSION}/${SOLANA_TARBALL}"
SOLANA_INSTALL_DIR="$HOME/.local/share/solana/install/active"
echo "Downloading Solana CLI v${SOLANA_VERSION} from ${SOLANA_DOWNLOAD_URL}"
# Use curl -L to follow redirects and -o to specify output file
curl -L --output "${SOLANA_TARBALL}" "${SOLANA_DOWNLOAD_URL}" || { echo "Error: Failed to download Solana CLI tarball from GitHub Releases."; exit 1; }
echo "Extracting Solana CLI to ${SOLANA_INSTALL_DIR}"
mkdir -p "${SOLANA_INSTALL_DIR}"
# Extract the tarball, stripping the top-level component
tar -xf "${SOLANA_TARBALL}" -C "${SOLANA_INSTALL_DIR}" --strip-components=1 || { echo "Error: Failed to extract Solana CLI tarball."; exit 1; }
echo "Adding Solana CLI to PATH"
echo "${SOLANA_INSTALL_DIR}/bin" >> $GITHUB_PATH
# Verify that build-sbf is now in PATH and callable
echo "Verifying build-sbf availability..."
which build-sbf || { echo "Error: 'build-sbf' command not found in PATH after Solana CLI installation."; exit 1; }
build-sbf --version || { echo "Error: 'build-sbf' command is in PATH but not callable or returned an error."; exit 1; }
echo "'build-sbf' verified successfully."
- name: Build code
run: corepack yarn build # Also use 'corepack yarn' for the build step
- name: Check for uncommitted generated changes
run: |
# Check if there are any uncommitted changes after the build
if git status --porcelain | grep -q .; then
echo "Error: Generated code differences detected!"
echo "Please run 'yarn build' locally and commit the changes."
git status --porcelain # Show the specific files that are different
exit 1 # Fail the workflow
else
echo "No differences found in generated code. Build is clean."
fi