polkadot staking miner monitor: MVP part 1 (#14) #6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Polkadot Staking Miner Monitor CI | |
on: | |
push: | |
branches: | |
- master | |
tags: | |
- v* | |
pull_request: | |
branches: | |
- master | |
env: | |
IMAGE: paritytech/ci-unified:bullseye-1.77.0-2024-04-10-v20240408 | |
IMAGE_NAME: paritytech/polkadot-staking-miner-monitor | |
RUST_INFO: rustup show && cargo --version && rustup +nightly show && cargo +nightly --version | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
set-image: | |
# GitHub Actions does not allow using 'env' in a container context. | |
# This workaround sets the container image for each job using 'set-image' job output. | |
runs-on: ubuntu-latest | |
outputs: | |
IMAGE: ${{ steps.set_image.outputs.IMAGE }} | |
steps: | |
- id: set_image | |
run: echo "IMAGE=${{ env.IMAGE }}" >> $GITHUB_OUTPUT | |
check-fmt: | |
name: Check formatting | |
runs-on: ubuntu-latest | |
needs: [set-image] | |
container: ${{ needs.set-image.outputs.IMAGE }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Check formatting | |
run: | | |
${{ env.RUST_INFO }} | |
cargo fmt --all -- --check | |
check-clippy: | |
name: Clippy | |
runs-on: ubuntu-latest | |
needs: [set-image] | |
container: ${{ needs.set-image.outputs.IMAGE }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Cache Rust dependencies | |
uses: swatinem/rust-cache@v2 | |
with: | |
key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }} | |
- name: Run Clippy | |
run: | | |
${{ env.RUST_INFO }} | |
cargo clippy --all-targets | |
check-docs: | |
name: Check documentation | |
runs-on: ubuntu-latest | |
needs: [set-image] | |
container: ${{ needs.set-image.outputs.IMAGE }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Cache Rust dependencies | |
uses: swatinem/rust-cache@v2 | |
with: | |
key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }} | |
- name: Check documentation | |
run: | | |
${{ env.RUST_INFO }} | |
RUSTDOCFLAGS="--cfg docsrs --deny rustdoc::broken_intra_doc_links" cargo doc --verbose --workspace --no-deps --document-private-items --all-features | |
test: | |
name: Run tests | |
runs-on: ubuntu-latest | |
needs: [set-image] | |
container: ${{ needs.set-image.outputs.IMAGE }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Cache Rust dependencies | |
uses: swatinem/rust-cache@v2 | |
with: | |
key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }} | |
- name: Run tests on Ubuntu | |
run: | | |
${{ env.RUST_INFO }} | |
RUST_LOG=info cargo +stable test --workspace -- --nocapture | |
build: | |
name: Build binary | |
runs-on: ubuntu-latest | |
needs: [set-image] | |
container: ${{ needs.set-image.outputs.IMAGE }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Cache Rust dependencies | |
uses: swatinem/rust-cache@v2 | |
with: | |
key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }} | |
- name: Build staking-miner | |
run: | | |
${{ env.RUST_INFO }} | |
cargo build --release --locked | |
- name: Move polkadot-staking-miner-monitor binary | |
run: mv ./target/release/polkadot-staking-miner-monitor . | |
- name: Collect artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: build-artifacts | |
path: | | |
./polkadot-staking-miner-monitor | |
./Dockerfile | |
build-docker-image: | |
name: Test Docker image build | |
if: ${{ github.event_name == 'pull_request' }} | |
runs-on: ubuntu-latest | |
needs: [check-fmt, | |
check-clippy, | |
check-docs, | |
test, | |
build] | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Download artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: build-artifacts | |
path: ./artifacts | |
- name: Set permissions | |
run: chmod +x ./artifacts/polkadot-staking-miner-monitor | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build Docker image | |
uses: docker/build-push-action@v6 | |
with: | |
push: false | |
context: ./artifacts | |
file: ./artifacts/Dockerfile | |
build-args: | | |
VCS_REF="${{ github.sha }}" | |
BUILD_DATE="$(date -u '+%Y-%m-%dT%H:%M:%SZ')" | |
tags: | | |
${{ env.IMAGE_NAME }}:test | |
publish-docker-image: | |
name: Build and publish Docker image | |
if: ${{ github.ref == 'refs/heads/master' || github.ref_type == 'tag' }} | |
runs-on: ubuntu-latest | |
environment: master_and_tags | |
needs: [check-fmt, | |
check-clippy, | |
check-docs, | |
test, | |
build] | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Download artifacts | |
uses: actions/download-artifact@v3 | |
with: | |
name: build-artifacts | |
path: ./artifacts | |
- name: Prepare Docker environment | |
run: | | |
echo IMAGE_TAG=$(if [ "$GITHUB_REF" == "refs/heads/master" ]; then echo "master-${GITHUB_SHA::7}"; else echo "$GITHUB_REF_NAME"; fi) >> $GITHUB_ENV | |
echo PUSH_IMAGE=true >> $GITHUB_ENV | |
echo "Docker image will be published with the tag: ${{ env.IMAGE_TAG }}!" | |
chmod +x ./artifacts/polkadot-staking-miner-monitor | |
- name: Log in to Docker Hub | |
if: ${{ github.ref == 'refs/heads/master' || github.ref_type == 'tag' }} | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v6 | |
with: | |
push: true | |
context: ./artifacts | |
file: ./artifacts/Dockerfile | |
build-args: | | |
VCS_REF="${{ github.sha }}" | |
BUILD_DATE="$(date -u '+%Y-%m-%dT%H:%M:%SZ')" | |
tags: | | |
${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} | |
${{ env.IMAGE_NAME }}:latest |