Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes to CI #701

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 88 additions & 75 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ jobs:
path: ./artifacts/
if-no-files-found: error


build_schemas:
if: contains('["crnbarr93", "SlayerAnsh", "joemonem", "DimitrijeDragasevic", "cowboy0015"]', github.actor)
runs-on: ubuntu-latest
Expand Down Expand Up @@ -111,83 +110,96 @@ jobs:
./andromeda-deploy

trigger-schema-parser:
needs: [deploy]
runs-on: ubuntu-latest
steps:
- name: Set Branch Based on Kernel
id: check-kernel
run: |
KERNEL_ADDRESS="${{ inputs.kernel_address }}"
TESTNET_KERNELS="${{ vars.TESTNET_KERNELS }}"
TESTNET_STAGING_KERNELS="${{ vars.TESTNET_STAGING_KERNELS }}"

if [[ "${KERNEL_ADDRESS}" == "${TESTNET_KERNELS}" ]]; then
needs: [deploy]
runs-on: ubuntu-latest
outputs:
should_continue: ${{ steps.check-kernel.outputs.should_continue }}
steps:
- name: Set Branch Based on Kernel
id: check-kernel
run: |
KERNEL_ADDRESS="${{ inputs.kernel_address }}"
IFS=',' read -ra TESTNET_KERNELS_ARR <<< "${{ vars.TESTNET_KERNELS }}"
IFS=',' read -ra TESTNET_STAGING_KERNELS_ARR <<< "${{ vars.TESTNET_STAGING_KERNELS }}"

for kernel in "${TESTNET_KERNELS_ARR[@]}"; do
if [[ "${KERNEL_ADDRESS}" == "${kernel}" ]]; then
echo "branch=develop" >> $GITHUB_OUTPUT
elif [[ "${KERNEL_ADDRESS}" == "${TESTNET_STAGING_KERNELS}" ]]; then
echo "branch=testnet-staging" >> $GITHUB_OUTPUT
else
echo "Error: Kernel not found in known configurations"
exit 1
echo "should_continue=true" >> $GITHUB_OUTPUT
exit 0
fi
done

- name: Checkout Schema Parser
uses: actions/checkout@v4
with:
repository: andromedaprotocol/schema-parser
ref: ${{ steps.check-kernel.outputs.branch }}
token: ${{ secrets.CI_PAT }}

- name: Download Schemas
uses: actions/download-artifact@v4
with:
name: temp-schemas
path: "packages/schema-parser/schema"

- uses: pnpm/action-setup@v4
with:
version: 8

- uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'pnpm'

- name: Process Schema
working-directory: packages/schema-parser
run: |
set -eo pipefail
echo "Installing dependencies..."
pnpm install
echo "Processing schema..."
npm run start
echo "Flattening schema..."
npm run flatten
echo "Exporting schema..."
npm run export

- name: Commit and Push Changes
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'

if [[ -n $(git status --porcelain) ]]; then
git add .
git commit -m "chore: Update schema for kernel: ${{ inputs.kernel_address }}"
git push
else
echo "No changes to commit"
for kernel in "${TESTNET_STAGING_KERNELS_ARR[@]}"; do
if [[ "${KERNEL_ADDRESS}" == "${kernel}" ]]; then
echo "branch=testnet-staging" >> $GITHUB_OUTPUT
echo "should_continue=true" >> $GITHUB_OUTPUT
exit 0
fi
done

echo "Skip: Kernel not found in known configurations"
echo "should_continue=false" >> $GITHUB_OUTPUT

Comment on lines +121 to +143
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance shell script robustness and error handling

While the array-based kernel checking is well-designed, let's improve the shell script robustness:

- KERNEL_ADDRESS="${{ inputs.kernel_address }}"
+ KERNEL_ADDRESS="${{ inputs.kernel_address || '' }}"
  
- IFS=',' read -ra TESTNET_KERNELS_ARR <<< "${{ vars.TESTNET_KERNELS }}"
- IFS=',' read -ra TESTNET_STAGING_KERNELS_ARR <<< "${{ vars.TESTNET_STAGING_KERNELS }}"
+ if [[ -z "${{ vars.TESTNET_KERNELS }}" ]] || [[ -z "${{ vars.TESTNET_STAGING_KERNELS }}" ]]; then
+   echo "Error: Required kernel environment variables are not set"
+   exit 1
+ fi
+ 
+ IFS=',' read -ra TESTNET_KERNELS_ARR <<< "${{ vars.TESTNET_KERNELS }}"
+ IFS=',' read -ra TESTNET_STAGING_KERNELS_ARR <<< "${{ vars.TESTNET_STAGING_KERNELS }}"
+ 
+ if [[ -z "${KERNEL_ADDRESS}" ]]; then
+   echo "Error: Kernel address is required"
+   echo "should_continue=false" >> $GITHUB_OUTPUT
+   exit 1
+ fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
KERNEL_ADDRESS="${{ inputs.kernel_address }}"
IFS=',' read -ra TESTNET_KERNELS_ARR <<< "${{ vars.TESTNET_KERNELS }}"
IFS=',' read -ra TESTNET_STAGING_KERNELS_ARR <<< "${{ vars.TESTNET_STAGING_KERNELS }}"
for kernel in "${TESTNET_KERNELS_ARR[@]}"; do
if [[ "${KERNEL_ADDRESS}" == "${kernel}" ]]; then
echo "branch=develop" >> $GITHUB_OUTPUT
elif [[ "${KERNEL_ADDRESS}" == "${TESTNET_STAGING_KERNELS}" ]]; then
echo "branch=testnet-staging" >> $GITHUB_OUTPUT
else
echo "Error: Kernel not found in known configurations"
exit 1
echo "should_continue=true" >> $GITHUB_OUTPUT
exit 0
fi
done
- name: Checkout Schema Parser
uses: actions/checkout@v4
with:
repository: andromedaprotocol/schema-parser
ref: ${{ steps.check-kernel.outputs.branch }}
token: ${{ secrets.CI_PAT }}
- name: Download Schemas
uses: actions/download-artifact@v4
with:
name: temp-schemas
path: "packages/schema-parser/schema"
- uses: pnpm/action-setup@v4
with:
version: 8
- uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'pnpm'
- name: Process Schema
working-directory: packages/schema-parser
run: |
set -eo pipefail
echo "Installing dependencies..."
pnpm install
echo "Processing schema..."
npm run start
echo "Flattening schema..."
npm run flatten
echo "Exporting schema..."
npm run export
- name: Commit and Push Changes
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
if [[ -n $(git status --porcelain) ]]; then
git add .
git commit -m "chore: Update schema for kernel: ${{ inputs.kernel_address }}"
git push
else
echo "No changes to commit"
for kernel in "${TESTNET_STAGING_KERNELS_ARR[@]}"; do
if [[ "${KERNEL_ADDRESS}" == "${kernel}" ]]; then
echo "branch=testnet-staging" >> $GITHUB_OUTPUT
echo "should_continue=true" >> $GITHUB_OUTPUT
exit 0
fi
done
echo "Skip: Kernel not found in known configurations"
echo "should_continue=false" >> $GITHUB_OUTPUT
KERNEL_ADDRESS="${{ inputs.kernel_address || '' }}"
if [[ -z "${{ vars.TESTNET_KERNELS }}" ]] || [[ -z "${{ vars.TESTNET_STAGING_KERNELS }}" ]]; then
echo "Error: Required kernel environment variables are not set"
exit 1
fi
IFS=',' read -ra TESTNET_KERNELS_ARR <<< "${{ vars.TESTNET_KERNELS }}"
IFS=',' read -ra TESTNET_STAGING_KERNELS_ARR <<< "${{ vars.TESTNET_STAGING_KERNELS }}"
if [[ -z "${KERNEL_ADDRESS}" ]]; then
echo "Error: Kernel address is required"
echo "should_continue=false" >> $GITHUB_OUTPUT
exit 1
fi
for kernel in "${TESTNET_KERNELS_ARR[@]}"; do
if [[ "${KERNEL_ADDRESS}" == "${kernel}" ]]; then
echo "branch=develop" >> $GITHUB_OUTPUT
echo "should_continue=true" >> $GITHUB_OUTPUT
exit 0
fi
done
for kernel in "${TESTNET_STAGING_KERNELS_ARR[@]}"; do
if [[ "${KERNEL_ADDRESS}" == "${kernel}" ]]; then
echo "branch=testnet-staging" >> $GITHUB_OUTPUT
echo "should_continue=true" >> $GITHUB_OUTPUT
exit 0
fi
done
echo "Skip: Kernel not found in known configurations"
echo "should_continue=false" >> $GITHUB_OUTPUT

- name: Checkout Schema Parser
uses: actions/checkout@v4
with:
repository: andromedaprotocol/schema-parser
ref: ${{ steps.check-kernel.outputs.branch }}
token: ${{ secrets.CI_PAT }}

- name: Download Schemas
uses: actions/download-artifact@v4
with:
name: temp-schemas
path: "packages/schema-parser/schema"

trigger-armour-workflow:
- uses: pnpm/action-setup@v4
with:
version: 8

- uses: actions/setup-node@v4
with:
node-version: "18"
cache: "pnpm"

- name: Process Schema
working-directory: packages/schema-parser
run: |
set -eo pipefail
echo "Installing dependencies..."
pnpm install
echo "Processing schema..."
npm run start
echo "Flattening schema..."
npm run flatten
echo "Exporting schema..."
npm run export

- name: Commit and Push Changes
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'

if [[ -n $(git status --porcelain) ]]; then
git add .
git commit -m "chore: Update schema for kernel: ${{ inputs.kernel_address }}"
git push
else
echo "No changes to commit"
fi

trigger-armour-workflow:
needs: [trigger-schema-parser]
if: needs.trigger-schema-parser.outputs.should_continue == 'true'
runs-on: ubuntu-latest
steps:
- name: Wait for schema updates
run: |
echo "Waiting 6 minutes for schema updates to propagate..."
sleep 360
echo "Wait complete, proceeding with Armor workflow trigger"

- name: Download version-map
uses: actions/download-artifact@v4
with:
Expand All @@ -198,41 +210,42 @@ jobs:
run: |
cd artifacts
cat version_map.json
cp version_map.json ../version_map.json
cp version_map.json ../version_map.json

- name: Trigger Armor Workflow
uses: actions/github-script@v7
with:
github-token: ${{ secrets.CI_PAT }}
script: |
const kernelAddress = '${{ inputs.kernel_address }}';
const testnetKernels = '${{ vars.TESTNET_KERNELS }}';
const testnetStagingKernels = '${{ vars.TESTNET_STAGING_KERNELS }}';
const testnetKernelsList = '${{ vars.TESTNET_KERNELS }}'.split(',');
const testnetStagingKernelsList = '${{ vars.TESTNET_STAGING_KERNELS }}'.split(',');

// Read the version map
const fs = require('fs');
const versionMap = fs.readFileSync('version_map.json', 'utf8');

let workflowFile;
if (kernelAddress === testnetKernels) {
if (testnetKernelsList.includes(kernelAddress)) {
workflowFile = 'develop.yml';
} else if (kernelAddress === testnetStagingKernels) {
} else if (testnetStagingKernelsList.includes(kernelAddress)) {
workflowFile = 'staging.yml';
} else {
core.setFailed('Error: Kernel not found in known configurations');
return;
}
Comment on lines +229 to 236
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance workflow file selection error handling

  let workflowFile;
  if (testnetKernelsList.includes(kernelAddress)) {
    workflowFile = 'develop.yml';
  } else if (testnetStagingKernelsList.includes(kernelAddress)) {
    workflowFile = 'staging.yml';
  } else {
-   core.setFailed('Error: Kernel not found in known configurations');
+   core.setFailed(`Error: Kernel ${kernelAddress} not found in known configurations. Available kernels: Testnet [${testnetKernelsList}], Staging [${testnetStagingKernelsList}]`);
    return;
  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (testnetKernelsList.includes(kernelAddress)) {
workflowFile = 'develop.yml';
} else if (kernelAddress === testnetStagingKernels) {
} else if (testnetStagingKernelsList.includes(kernelAddress)) {
workflowFile = 'staging.yml';
} else {
core.setFailed('Error: Kernel not found in known configurations');
return;
}
if (testnetKernelsList.includes(kernelAddress)) {
workflowFile = 'develop.yml';
} else if (testnetStagingKernelsList.includes(kernelAddress)) {
workflowFile = 'staging.yml';
} else {
core.setFailed(`Error: Kernel ${kernelAddress} not found in known configurations. Available kernels: Testnet [${testnetKernelsList}], Staging [${testnetStagingKernelsList}]`);
return;
}


try {
await github.rest.actions.createWorkflowDispatch({
owner: 'andromedaprotocol',
repo: 'andromeda-armour',
workflow_id: workflowFile,
ref: 'main',
inputs: {
version_map: versionMap
version_map: versionMap,
grep: '@smoke_test'
}
});
} catch (error) {
core.setFailed(`Failed to trigger Armor workflow: ${error.message}`);
}
}
Loading