Skip to content

CI/CD Pipeline

CI/CD Pipeline #673

Workflow file for this run

name: CI/CD Pipeline
on:
push:
branches: [master, next]
tags:
- "v*"
pull_request:
branches: [master, next]
schedule:
- cron: "0 0 * * *" # Daily at midnight UTC
workflow_dispatch:
env:
DOCKER_TLS_CERTDIR: "/certs"
DOCKER_HOST: tcp://docker:2376
DOCKER_DRIVER: overlay2
IMAGE_SHA: ${{ github.repository }}:${{ github.sha }}
jobs:
lint-format-typecheck:
name: Lint - Format - Typecheck
continue-on-error: true
runs-on: ubuntu-latest
strategy:
matrix:
package: [pragma-utils, pragma-sdk, price-pusher, vrf-listener]
steps:
- uses: actions/checkout@v3
- uses: CfirTsabari/actions-pipx@v1
- name: Install poetry
run: pipx install poetry
- name: Set up Python 3.12.4
uses: actions/setup-python@v4
with:
python-version: "3.12.4"
cache: "poetry"
- name: Install dependencies
run: |
cd ${{ matrix.package }}
poetry install
- name: Check poetry.lock
run: |
cd ${{ matrix.package }}
poetry lock --check
- name: Lint
run: |
cd ${{ matrix.package }}
poetry run poe lint
- name: Format
run: |
cd ${{ matrix.package }}
poetry run poe format_check
- name: Typecheck
run: |
cd ${{ matrix.package }}
poetry run poe typecheck
tests:
name: Run Tests
continue-on-error: true
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12.4"]
package: [pragma-utils, pragma-sdk, price-pusher, vrf-listener]
steps:
- uses: actions/checkout@v3
with:
submodules: "true"
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- uses: CfirTsabari/actions-pipx@v1
- name: Install poetry
run: pipx install poetry
- name: Install dependencies
run: |
cd ${{ matrix.package }}
poetry install
- name: Cache contracts
id: cache-contracts
uses: actions/cache@v3
with:
path: ./pragma-oracle/target
key: ${{ runner.os }}-contracts-${{ hashFiles('./pragma-oracle/src', 'poetry.lock') }}
- uses: software-mansion/setup-scarb@v1
with:
tool-versions: pragma-oracle/.tool-versions
- name: Compile contracts
if: steps.cache-contracts.outputs.cache-hit != 'true'
working-directory: ./pragma-oracle
run: |
scarb -V
scarb build
- name: Check ABIs are up-to-date
run: |
# Find and compare *.sierra.json files in both directories
for file in $(find ./pragma-oracle/target/dev -type f -name "*.sierra.json"); do
# Extract the relative path of the file for comparison
rel_path=${file#./pragma-oracle/target/dev}
# Use diff to compare the file with its counterpart in the SDK directory
diff "$file" "pragma-sdk/pragma_sdk/onchain/abis$rel_path" || (echo "Error: $rel_path in pragma-oracle/target does not match with pragma-sdk/pragma_sdk/onchain/abis/" && exit 1)
done
- name: Install rust
run: |
curl https://sh.rustup.rs -sSf | sh -s -- -y
source $HOME/.cargo/env
- name: Verify Rust and Cargo installation
run: |
rustc --version
cargo --version
- uses: Swatinem/rust-cache@v2
- name: Install starknet-devnet
run: cargo install starknet-devnet
# Add any package-specific setup steps here
- name: Run tests
run: |
cd ${{ matrix.package }}
poetry run poe test_all
# TODO: re-add this
# - name: Generate coverage in XML
# run: |
# cd ${{ matrix.package }}
# poetry run coverage xml
# - name: Upload coverage to Codecov
# uses: codecov/codecov-action@v3
# env:
# CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
build_packages:
needs: [lint-format-typecheck, tests]
strategy:
matrix:
package: [pragma-utils, pragma-sdk, price-pusher, vrf-listener]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.12.4
- uses: actions/checkout@v3
- uses: CfirTsabari/actions-pipx@v1
- name: Install poetry
run: pipx install poetry
- name: Build package
run: |
cd ${{ matrix.package }}
poetry install --sync
poetry build
- name: Upload artifacts
uses: actions/upload-artifact@v2
with:
name: ${{ matrix.package }}-dist
path: ${{ matrix.package }}/dist
build_containers:
needs: build_packages
strategy:
matrix:
package: [price-pusher] # Add other packages that need containers here
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
registry: ${{ secrets.DOCKER_REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Download artifacts
uses: actions/download-artifact@v2
with:
name: ${{ matrix.package }}-dist
path: ${{ matrix.package }}/dist
- name: Build and push
uses: docker/build-push-action@v2
with:
context: ./${{ matrix.package }}
push: true
tags: ${{ env.IMAGE_SHA }}
release:
needs: [build_packages, build_containers]
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.12.4
- name: Install twine
run: pip install --upgrade twine
- name: Download all artifacts
uses: actions/download-artifact@v2
- name: Publish to PyPI
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: twine upload **/dist/*
- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body_path: CHANGELOG.md
draft: false
prerelease: false
bump_version:
needs: [build_packages, build_containers]
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.12.4
- name: Install Commitizen
run: pip install --upgrade Commitizen
- name: Configure Git
run: |
git config user.name github-actions
git config user.email github-actions@github.com
- name: Bump version
run: |
git fetch --tags
cz bump --retry || echo "probably nothing to do"
- name: Push changes
run: |
TAG=$(git tag --points-at HEAD)
if [[ $TAG ]]; then
echo "Version bumped to $TAG"
git push
git push --tags
else
echo "Version NOT bumped"
fi