Skip to content

Commit

Permalink
feat: ci.yml and cd.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
skylar-simoncelli authored Sep 26, 2024
1 parent 3e0963e commit 7208ae2
Show file tree
Hide file tree
Showing 49 changed files with 2,171 additions and 1,148 deletions.
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export CARDANO_CONFIG_DIR="$(pwd)/docker/config"
export KUPO_WORKDIR="$RUN_DIR/kupo-db"
mkdir -p $KUPO_WORKDIR

source devnet/.envrc
source envs/devnet/.envrc

if [[ -f "$PWD/.envrc.local" ]]; then
echo using local envrc
Expand Down
106 changes: 106 additions & 0 deletions .github/actions/artifacts/build-pc-artifacts/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
name: "Build and Upload PC Artifacts"
description: "Build and upload partner-chains artifacts for Linux, macOS x86_64, and macOS arm64"
inputs:
sha:
description: "partner-chains commit SHA or branch to build from"
required: true
tag:
description: "partner-chains release tag to append to artifact name"
required: true
os:
description: "Operating system for the build (linux, macos-x86_64, macos-arm64)"
required: true

runs:
using: "composite"
steps:
- name: Set filename variables
shell: bash
run: |
if [[ "${{ inputs.os }}" == "linux" ]]; then
echo "PARTNER_CHAINS_CLI=partner-chains-cli-${{ inputs.tag }}-x86_64-linux" >> $GITHUB_ENV
echo "PARTNER_CHAINS_NODE=partner-chains-node-${{ inputs.tag }}-x86_64-linux" >> $GITHUB_ENV
elif [[ "${{ inputs.os }}" == "macos-x86_64" ]]; then
echo "PARTNER_CHAINS_CLI=partner-chains-cli-${{ inputs.tag }}-x86_64-apple-darwin" >> $GITHUB_ENV
echo "PARTNER_CHAINS_NODE=partner-chains-node-${{ inputs.tag }}-x86_64-apple-darwin" >> $GITHUB_ENV
elif [[ "${{ inputs.os }}" == "macos-arm64" ]]; then
echo "PARTNER_CHAINS_CLI=partner-chains-cli-${{ inputs.tag }}-aarch64-apple-darwin" >> $GITHUB_ENV
echo "PARTNER_CHAINS_NODE=partner-chains-node-${{ inputs.tag }}-aarch64-apple-darwin" >> $GITHUB_ENV
fi
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ inputs.sha }}

- name: Install protoc
shell: bash
run: |
if [[ "${{ inputs.os }}" == "linux" ]]; then
sudo apt-get install -y protobuf-compiler
elif [[ "${{ inputs.os }}" == "macos-x86_64" ]]; then
curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v21.3/protoc-21.3-osx-x86_64.zip
unzip protoc-21.3-osx-x86_64.zip -d $HOME/protoc
sudo mv $HOME/protoc/bin/protoc /usr/local/bin/protoc
elif [[ "${{ inputs.os }}" == "macos-arm64" ]]; then
curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v21.3/protoc-21.3-osx-aarch_64.zip
unzip protoc-21.3-osx-aarch_64.zip -d $HOME/protoc
sudo mv $HOME/protoc/bin/protoc /usr/local/bin/protoc
fi
- name: Build partner-chains-node
run: |
if [[ "${{ inputs.os }}" == "linux" ]]; then
rustup target add x86_64-unknown-linux-gnu
cargo build -p partner-chains-node --locked --release --target x86_64-unknown-linux-gnu
cp target/x86_64-unknown-linux-gnu/release/partner-chains-node $PARTNER_CHAINS_NODE
elif [[ "${{ inputs.os }}" == "macos-x86_64" ]]; then
rustup target add x86_64-apple-darwin
cargo build -p partner-chains-node --locked --release --target x86_64-apple-darwin
cp target/x86_64-apple-darwin/release/partner-chains-node $PARTNER_CHAINS_NODE
elif [[ "${{ inputs.os }}" == "macos-arm64" ]]; then
rustup target add aarch64-apple-darwin
cargo build -p partner-chains-node --locked --release --target aarch64-apple-darwin
cp target/aarch64-apple-darwin/release/partner-chains-node $PARTNER_CHAINS_NODE
fi
shell: bash

- name: Test partner-chains-node
shell: bash
run: |
if [[ "${{ inputs.os }}" == "linux" ]]; then
cargo test --locked --release --target x86_64-unknown-linux-gnu
elif [[ "${{ inputs.os }}" == "macos-x86_64" ]]; then
cargo test --locked --release --target x86_64-apple-darwin
elif [[ "${{ inputs.os }}" == "macos-arm64" ]]; then
cargo test --locked --release --target aarch64-apple-darwin
fi
- name: Build partner-chains-cli
shell: bash
run: |
if [[ "${{ inputs.os }}" == "linux" ]]; then
rustup target add x86_64-unknown-linux-gnu
cargo build -p partner-chains-cli --locked --release --target x86_64-unknown-linux-gnu
cp target/x86_64-unknown-linux-gnu/release/partner-chains-cli $PARTNER_CHAINS_CLI
elif [[ "${{ inputs.os }}" == "macos-x86_64" ]]; then
rustup target add x86_64-apple-darwin
cargo build -p partner-chains-cli --locked --release --target x86_64-apple-darwin
cp target/x86_64-apple-darwin/release/partner-chains-cli $PARTNER_CHAINS_CLI
elif [[ "${{ inputs.os }}" == "macos-arm64" ]]; then
rustup target add aarch64-apple-darwin
cargo build -p partner-chains-cli --locked --release --target aarch64-apple-darwin
cp target/aarch64-apple-darwin/release/partner-chains-cli $PARTNER_CHAINS_CLI
fi
- name: Upload partner-chains-cli artifact
uses: actions/upload-artifact@v4
with:
name: partner-chains-cli-${{ inputs.os }}-artifact
path: ${{ env.PARTNER_CHAINS_CLI }}

- name: Upload partner-chains-node artifact
uses: actions/upload-artifact@v4
with:
name: partner-chains-node-${{ inputs.os }}-artifact
path: ${{ env.PARTNER_CHAINS_NODE }}
55 changes: 55 additions & 0 deletions .github/actions/artifacts/download-pcsc-artifact/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: "Parse Flake and Download PCSC Release"
description: "Extracts PCSC release info from flake.nix, constructs an artifact name, downloads, and uploads the artifact"
inputs:
sha:
description: "SHA or branch to checkout"
required: true

runs:
using: "composite"
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ inputs.sha }}

- name: Extract PCSC Release Info from flake.nix
shell: bash
id: extract-release
run: |
echo "Extracting PCSC release version from flake.nix..."
release=$(grep -Po 'url = "github:input-output-hk/partner-chains-smart-contracts/v\K[0-9.]+(?=";)' flake.nix)
echo "Release version: v$release"
echo "::set-output name=release::v$release"
- name: Construct Artifact Name
shell: bash
id: construct-artifact
run: |
version_without_v=${{ steps.extract-release.outputs.release#v }}
artifact="trustless-sidechain-cli-${version_without_v}-x86_64-linux.zip"
echo "Constructed artifact name: $artifact"
echo "::set-output name=artifact::$artifact"
- name: Download Artifact as zipped.zip
shell: bash
run: |
wget -O zipped.zip "https://github.com/input-output-hk/partner-chains-smart-contracts/releases/download/${{ steps.extract-release.outputs.release }}/${{ steps.construct-artifact.outputs.artifact }}"
- name: Extract zipped.zip to a temporary directory
shell: bash
run: |
mkdir temp_dir
unzip zipped.zip -d temp_dir
- name: Rename extracted directory to partner-chains-smart-contracts
shell: bash
run: |
original_dir=$(ls temp_dir)
mv "temp_dir/$original_dir" partner-chains-smart-contracts
- name: Upload Extracted Artifact
uses: actions/upload-artifact@v4
with:
name: partner-chains-smart-contracts-artifact
path: partner-chains-smart-contracts
35 changes: 35 additions & 0 deletions .github/actions/artifacts/generate-chain-specs/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: "Generate Chain Specs from Node Binary"
description: "Downloads the partner-chains node binary, generates chain specs for different environments, and uploads them."
inputs:
sha:
description: "Commit SHA to append to chain spec secret name"
required: true

runs:
using: "composite"
steps:
- name: Download Linux partner-chains-node artifact
uses: actions/download-artifact@v4
with:
name: partner-chains-node-x86_64-linux-artifact-artifact
path: ./

- name: Generate Chain Specs
shell: bash
run: |
chmod +x ./partner-chains-node
source ./envs/devnet/.envrc
./partner-chains-node build-spec --chain local --disable-default-bootnode --raw > devnet_chain_spec.json
source ./envs/staging-preview/.envrc
./partner-chains-node build-spec --chain staging --disable-default-bootnode --raw > staging_preview_chain_spec.json
source ./envs/staging-preprod/.envrc
./partner-chains-node build-spec --chain staging --disable-default-bootnode --raw > staging_preprod_chain_spec.json
- name: Upload Chain Specs
uses: actions/upload-artifact@v4
with:
name: chain-specs
path: |
devnet_chain_spec.json
staging_preview_chain_spec.json
staging_preprod_chain_spec.json
26 changes: 26 additions & 0 deletions .github/actions/deploy/argocd/deploy-argocd/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: "Deploy ArgoCD Node"
description: "Deploys an ArgoCD node using a specified commit SHA."
inputs:
sha:
description: "Commit SHA"
required: true

outputs: {}

runs:
using: "composite"
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Create and Push Manifest
env:
GH_TOKEN: ${{ env.ACTIONS_PAT }}
run: |
cd .github/actions/deploy/argocd/
bash generate-manifest.sh ${{ inputs.sha }}
shell: bash

- name: Wait for 8.5 minutes (ArgoCD refresh interval is 15s + 15s to build + 60s for node to start producing blocks)
run: sleep 90
shell: bash
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ gh api "$ARGOCD_REPO_API_ENDPOINT" \
--method PUT \
--field message="$MESSAGE" \
--field content="$CONTENT" \
--field branch="$BRANCH_NAME"
--field branch="$BRANCH_NAME"
File renamed without changes.
52 changes: 52 additions & 0 deletions .github/actions/deploy/argocd/teardown-argocd/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: "Teardown ArgoCD Environment"
description: "Tears down an ArgoCD environment by removing an ephemeral environment file."
inputs:
sha:
description: "SHA of the commit"
required: true

outputs: {}

runs:
using: "composite"
steps:
- name: Checkout ArgoCD Repository
uses: actions/checkout@v4
with:
repository: input-output-hk/sidechains-argocd
token: ${{ env.ACTIONS_PAT }}
path: sidechains-argocd

- name: Delete Ephemeral Environment File
uses: actions/github-script@v7
with:
github-token: ${{ env.ACTIONS_PAT }}
script: |
const fs = require('fs');
const path = require('path');
const directory = 'sidechains-argocd/integration-testing';
const targetFile = `manifest-sha-${{ inputs.sha }}.yaml`;
const filePath = path.join(directory, targetFile);
if (fs.existsSync(filePath)) {
console.log(`Deleting file: ${targetFile}`);
const shaResponse = await github.rest.repos.getContent({
owner: 'input-output-hk',
repo: 'sidechains-argocd',
path: `integration-testing/${targetFile}`,
});
const fileSha = shaResponse.data.sha;
await github.rest.repos.deleteFile({
owner: 'input-output-hk',
repo: 'sidechains-argocd',
path: `integration-testing/${targetFile}`,
message: `ci: Tear down integration-testing environment for SHA ${{ inputs.sha }}`,
sha: fileSha,
branch: 'main'
});
} else {
console.log(`File not found: ${targetFile}`);
}
51 changes: 51 additions & 0 deletions .github/actions/deploy/deploy-rustdoc/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: "Deploy Rust Docs"
description: "Installs necessary tooling, generates Rust documentation, and deploys it to GitHub Pages."
inputs:
ssh_key:
description: "SSH key to read Substrate Repo"
required: true

outputs: {}

runs:
using: "composite"
steps:
- name: Install tooling
run: |
sudo apt-get update
sudo apt-get install -y protobuf-compiler
protoc --version
shell: bash

- name: Checkout repository
uses: actions/checkout@v4

- name: Add SSH key to read Substrate Repo
run: |
mkdir -p ~/.ssh
ssh-keyscan github.com >> ~/.ssh/known_hosts
ssh-agent -a /tmp/ssh_agent.sock > /dev/null
ssh-add - <<< "${{ inputs.ssh_key }}"
shell: bash

- name: Rust versions
run: rustup show
shell: bash

- name: Rust cache
uses: Swatinem/[email protected]

- name: Build rustdocs
run: SKIP_WASM_BUILD=1 cargo doc --all --no-deps
shell: bash

- name: Make index.html
run: echo "<meta http-equiv=refresh content=0;url=node_template/index.html>" > ./target/doc/index.html
shell: bash

- name: Deploy documentation
if: ${{ github.ref_name == 'master' }}
uses: peaceiris/[email protected]
with:
publish_branch: gh-pages
publish_dir: ./target/doc
Loading

0 comments on commit 7208ae2

Please sign in to comment.