Skip to content

Extract code snippets and reference them from doc files (Part 2 of 2) #123

Extract code snippets and reference them from doc files (Part 2 of 2)

Extract code snippets and reference them from doc files (Part 2 of 2) #123

Workflow file for this run

name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push events but only for the "main" branch
push:
branches: [ main ]
pull_request:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
sdk-ref:
description: 'sdk commit/tag/branch reference. Defaults to main.'
required: false
type: string
default: main
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
jobs:
setup:
name: setup
runs-on: ubuntu-latest
outputs:
sdk-ref: ${{ inputs.sdk-ref || '0.2.7' }}
package-version: '0.2.7'
steps:
- run: echo "set pre-setup output variables"
build-packages:
needs: setup
name: build packages
uses: breez/breez-sdk/.github/workflows/publish-all-platforms.yml@main
with:
repository: breez/breez-sdk
ref: ${{ needs.setup.outputs.sdk-ref }}
package-version: ${{ needs.setup.outputs.package-version }}
packages-to-publish: '["csharp", "flutter", "golang", "react-native"]'
use-dummy-binaries: true
check-rust:
needs: setup
name: Check rust snippets
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
# Set up Rust environment and run checks
- name: Install rust
run: |
rustup set auto-self-update disable
rustup toolchain install stable --profile minimal
- name: Install Protoc
uses: arduino/setup-protoc@v2
with:
version: "23.4"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: Swatinem/rust-cache@v2
with:
workspaces: snippets/rust -> snippets/rust/target
- name: temporarily get sdk
uses: actions/checkout@v3
with:
repository: breez/breez-sdk
ref: ${{ needs.setup.outputs.sdk-ref }}
path: breez-sdk
- id: rev-parse
name: get proper rev
working-directory: breez-sdk
run: |
rev=$(git rev-parse HEAD)
echo "$rev"
echo "rev=$rev" >> $GITHUB_OUTPUT
- name: set sdk version
working-directory: snippets/rust
run: |
cargo add --git https://github.com/breez/breez-sdk.git breez-sdk-core --rev "${{ steps.rev-parse.outputs.rev }}"
- name: clippy
working-directory: snippets/rust
run: |
# Explicitly allow clippy::dead_code lint because the functions aren't called in the docs snippets
# Explicitly allow clippy::unused_variables because snippets might have to demonstrate how to get certain variables without using them afterward
cargo clippy -- --allow dead_code --allow unused_variables --deny warnings
check-dart:
needs:
- setup
- build-packages
name: Check dart snippets
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
# Set up the flutter environment and run checks
- uses: subosito/flutter-action@v2
with:
flutter-version: '3.13.9'
channel: 'stable'
- uses: actions/download-artifact@v3
with:
name: breez-sdk-flutter-${{ needs.setup.outputs.package-version }}
path: snippets/dart_snippets/packages/breez-sdk-flutter
- name: pub-get
working-directory: snippets/dart_snippets
run: flutter pub get
- name: dart-analyze
working-directory: snippets/dart_snippets
run: dart analyze --fatal-infos
check-csharp:
needs:
- setup
- build-packages
name: Check C# snippets
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Setup dotnet
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.x'
- name: Download archived package
uses: actions/download-artifact@v3
with:
name: Breez.Sdk.${{ needs.setup.outputs.package-version }}.nupkg
path: .
- name: Create nuget package source
working-directory: snippets/csharp
run: |
mkdir packages
nuget add ../../Breez.Sdk.${{ needs.setup.outputs.package-version }}.nupkg -Source ./packages
- name: Add nuget dependency
working-directory: snippets/csharp
run: |
dotnet add package Breez.Sdk -s ./packages
- name: Build the csharp project
working-directory: snippets/csharp
run: dotnet build
check-react-native:
needs:
- setup
- build-packages
name: Check react native snippets
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Set Node.js 20.x
uses: actions/setup-node@v3
with:
node-version: 20.x
- name: Download archived package
uses: actions/download-artifact@v3
with:
name: react-native-${{ needs.setup.outputs.package-version }}
path: snippets/react-native/packages
- name: Install dependencies
working-directory: snippets/react-native
run: yarn
- name: Check syntax
working-directory: snippets/react-native
run: tsc
- name: Check formatting
working-directory: snippets/react-native
run: yarn run lint
check-golang:
needs:
- setup
- build-packages
name: Check Go snippets
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Download archived package
uses: actions/download-artifact@v3
with:
name: breez-sdk-go-${{ needs.setup.outputs.package-version }}
path: snippets/go/packages/breez-sdk-go
- name: Format the Go snippets
working-directory: snippets/go
run: go fmt
- name: Test formatted correctly
working-directory: snippets/go
run: |
status=$(git status --porcelain)
if [[ -n "$status" ]]; then
echo "Git status has changes"
echo "$status"
git diff
exit 1
else
echo "No changes in git status"
fi
- name: Build the Go snippets
working-directory: snippets/go
run: |
go get
go build .
build:
name: Build mdbook
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Install rust
run: |
rustup set auto-self-update disable
rustup toolchain install stable --profile minimal
- uses: Swatinem/rust-cache@v2
with:
workspaces: |
. -> target
snippets-processor -> snippets-processor/target
- name: Install dependencies
run: |
cargo install mdbook --vers "^0.4" --locked
cargo install --path ./snippets-processor
- name: Build mdbook
run: mdbook build
- name: Archive book
uses: actions/upload-artifact@v3
with:
name: book
path: book
- name: Push book to main-generated branch
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
run: |
git config --global user.name "Generator"
git config --global user.email "[email protected]"
git add -f book
git commit -m "Generate documentation"
git push origin --force main:main-generated
python:
name: Python
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.8'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ruff
# use pypi when published.
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple breez_sdk
- name: python-analyse with ruff
run: |
cd snippets/python_snippets/src
ruff --ignore F841 --ignore F401 --output-format=github .
- name: Test
run: |
cd snippets/python_snippets
python3 -m compileall src
continue-on-error: false