diff --git a/.github/issue_templates/nightly_run_failed.md b/.github/issue_templates/nightly_run_failed.md index ab66f95a9..06a299114 100644 --- a/.github/issue_templates/nightly_run_failed.md +++ b/.github/issue_templates/nightly_run_failed.md @@ -2,4 +2,4 @@ title: staking-miner integration tests failed against latest polkadot build. --- -Go to {{ env.GITLAB_PIPELINE_URL }} to see details about the failure. \ No newline at end of file +Go to [job logs]({{ env.FAILED_WORKFLOW_RUN_URL }}) to see details about the failure. \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..c28518e6c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,226 @@ +name: Polkadot Staking Miner CI + +on: + push: + branches: + - main + tags: + - v* + pull_request: + branches: + - main + +env: + IMAGE: paritytech/ci-unified:bullseye-1.74.0 + IMAGE_NAME: paritytech/staking-miner-v2 + 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 +nightly 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 + + check-cargo-hack: + name: Check code using cargo-hack + 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 code using cargo-hack + run: | + ${{ env.RUST_INFO }} + cargo hack check --workspace --each-feature --all-targets + + check-staking-miner-playground: + name: Check staking-miner-playground + 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 staking-miner-playground + run: | + ${{ env.RUST_INFO }} + cargo +nightly check --manifest-path staking-miner-playground/Cargo.toml + + 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 test --workspace -- --nocapture + + build: + name: Build polkadot-staking-miner 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 binary + run: mv ./target/release/polkadot-staking-miner . + + - name: Collect artifacts + uses: actions/upload-artifact@v3 + with: + name: build-artifacts + path: | + ./polkadot-staking-miner + ./Dockerfile + + publish: + name: Build/publish Docker image + runs-on: ubuntu-latest + needs: [check-fmt, + check-clippy, + check-docs, + check-cargo-hack, + check-staking-miner-playground, + 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: | + if [[ ${{ github.ref }} == 'refs/heads/main' ]] || [[ ${{ github.ref_type }} == 'tag' ]]; then + echo IMAGE_TAG=$(if [ "$GITHUB_REF" == "refs/heads/main" ]; then echo "main-${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 }}!" + else + echo IMAGE_TAG=stub_tag >> $GITHUB_ENV + echo PUSH_IMAGE=false >> $GITHUB_ENV + echo "Docker image will not be published. Just testing if the build works." + fi + chmod +x ./artifacts/polkadot-staking-miner + + - name: Log in to Docker Hub + 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/Push Docker image + uses: docker/build-push-action@v5 + with: + push: ${{ env.PUSH_IMAGE }} + 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 diff --git a/.github/workflows/gitspiegel-trigger.yml b/.github/workflows/gitspiegel-trigger.yml deleted file mode 100644 index dce3aaf2f..000000000 --- a/.github/workflows/gitspiegel-trigger.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: gitspiegel sync - -# This workflow doesn't do anything, it's only use is to trigger "workflow_run" -# webhook, that'll be consumed by gitspiegel -# This way, gitspiegel won't do mirroring, unless this workflow runs, -# and running the workflow is protected by GitHub - -on: - pull_request: - types: - - opened - - synchronize - - unlocked - - ready_for_review - - reopened - -jobs: - sync: - runs-on: ubuntu-latest - steps: - - name: Do nothing - run: echo "let's go" diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 43b63f213..7ce5bdc7b 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -1,34 +1,64 @@ -name: Daily compatibility check against latest polkadot +name: Nightly test on: + schedule: + - cron: '0 0 * * *' workflow_dispatch: - inputs: - gitlab_pipeline: - description: 'Link to failed pipeline' - required: true - gitlab_test_job_status: - description: 'GitLab test job status' - required: true jobs: - announce-status: + nightly-test: runs-on: ubuntu-latest - steps: - - name: Announce a status - run: echo ${{ inputs.gitlab_test_job_status }} - create-an-issue: - if: ${{ inputs.gitlab_test_job_status == 'failed' }} - runs-on: ubuntu-latest steps: - - name: Checkout staking-miner sources + - name: Checkout repository uses: actions/checkout@v4 - - name: Create an issue + - name: Free space on the runner + run: | + df -h + sudo apt -y autoremove --purge + sudo apt -y autoclean + sudo rm -rf /usr/share/dotnet + sudo rm -rf /opt/ghc + sudo rm -rf "/usr/local/share/boost" + sudo rm -rf "$AGENT_TOOLSDIRECTORY" + df -h + + - name: Cache Rust dependencies + uses: swatinem/rust-cache@v2 + with: + key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }} + cache-on-failure: true + + - name: Run nightly tests + run: | + sudo apt install -y protobuf-compiler + rustup target add wasm32-unknown-unknown + rustup component add rust-src + git clone -b master --depth 1 https://github.com/paritytech/polkadot-sdk.git polkadot-sdk + cd polkadot-sdk + cargo build -p polkadot --release --features fast-runtime + mkdir -p ~/.local/bin + sudo mv ./target/release/polkadot /usr/bin + sudo mv ./target/release/polkadot-execute-worker /usr/bin + sudo mv ./target/release/polkadot-prepare-worker /usr/bin + polkadot --version + cd - + rm -rf polkadot + cd staking-miner-playground + cargo build --release --features test-trimming + sudo mv ./target/release/staking-miner-playground /usr/bin + staking-miner-playground --version + cd - + RUST_LOG=info cargo test --workspace --all-features -- --nocapture + cargo clean + + - name: Create an issue on failure + if: failure() uses: JasonEtco/create-an-issue@v2 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - GITLAB_PIPELINE_URL: ${{ inputs.gitlab_pipeline }} + FAILED_WORKFLOW_RUN_URL: https://github.com/${{ github.repository }}/commit/${{ github.sha }}/checks/${{ github.run_id }} with: # Use this issue template: filename: .github/issue_templates/nightly_run_failed.md @@ -38,6 +68,3 @@ jobs: # Look for new *open* issues in this search (we want to # create a new one if we only find closed versions): search_existing: open - - - name: Fail workflow if tests failed - run: exit 1 diff --git a/.github/workflows/publish-docker-description.yml b/.github/workflows/publish-docker-description.yml new file mode 100644 index 000000000..c21fea004 --- /dev/null +++ b/.github/workflows/publish-docker-description.yml @@ -0,0 +1,24 @@ +name: Publish Docker image description + +on: + push: + branches: + - 'main' + paths: + - 'Dockerfile.README.md' + +jobs: + publish_docker_description: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Docker Hub Description + uses: paritytech-actions/dockerhub-description@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + repository: 'paritytech/staking-miner-v2' + short-description: 'polkadot-staking-miner' + readme-filepath: 'Dockerfile.README.md' \ No newline at end of file diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 3350e5534..000000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,237 +0,0 @@ -stages: - - check - - test - - nightly-test - - build - - publish - -default: - interruptible: true - retry: - max: 2 - when: - - runner_system_failure - - unknown_failure - - api_failure - -variables: - CI_IMAGE: "paritytech/ci-unified:bullseye-1.74.0-2023-11-01-v20231204" - # BUILDAH_IMAGE is defined in group variables - BUILDAH_COMMAND: "buildah --storage-driver overlay2" - -.common-refs: &common-refs - rules: - - if: $CI_PIPELINE_SOURCE == "schedule" - when: never - - if: $CI_PIPELINE_SOURCE == "web" - - if: $CI_COMMIT_REF_NAME == "main" - - if: $CI_COMMIT_REF_NAME =~ /^[0-9]+$/ # PRs - - if: $CI_COMMIT_REF_NAME =~ /^v[0-9]+\.[0-9]+.*$/ # i.e. v1.0, v2.1rc1 - -.publish-refs: &publish-refs - rules: - - if: '$CI_PIPELINE_SOURCE == "schedule"' - when: never - - if: $CI_COMMIT_REF_NAME == "main" - - if: $CI_COMMIT_REF_NAME =~ /^v[0-9]+\.[0-9]+.*$/ # i.e. v1.0, v2.1rc1 - -.rust-info-script: &rust-info-script - - rustup show - - cargo --version - - rustup +nightly show - - cargo +nightly --version - - bash --version - -.docker-env: &docker-env - image: "${CI_IMAGE}" - before_script: - - *rust-info-script - tags: - - linux-docker-vm-c2 - -.kubernetes-env: &kubernetes-env - image: "${CI_IMAGE}" - tags: - - kubernetes-parity-build - -.collect-artifacts: &collect-artifacts - artifacts: - name: "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}" - when: on_success - expire_in: 1 days - paths: - - ./artifacts/ - -#### stage: check - -fmt: - stage: check - <<: *docker-env - <<: *common-refs - script: - - cargo +nightly fmt --all -- --check - -clippy: - stage: check - <<: *docker-env - <<: *common-refs - script: - - cargo clippy --all-targets - -check-docs: - stage: check - <<: *docker-env - <<: *common-refs - script: - - RUSTDOCFLAGS="--cfg docsrs --deny rustdoc::broken_intra_doc_links" - cargo doc --verbose --workspace --no-deps --document-private-items --all-features - -check-code: - stage: check - <<: *docker-env - <<: *common-refs - script: - - cargo install cargo-hack - - cargo hack check --workspace --each-feature --all-targets - -check-staking-miner-playground: - stage: check - <<: *docker-env - <<: *common-refs - script: - - rustup target add wasm32-unknown-unknown --toolchain nightly - - cargo +nightly install wasm-gc - - cargo check --manifest-path staking-miner-playground/Cargo.toml - -### stage: test - -test-ubuntu: - stage: test - needs: [] - <<: *docker-env - <<: *common-refs - script: - - RUST_LOG=info cargo test --workspace -- --nocapture - -### stage: nightly-test - -nightly-test: - stage: nightly-test - <<: *docker-env - rules: - - if: $CI_PIPELINE_SOURCE == "schedule" - script: - - git clone -b master --depth 1 https://github.com/paritytech/polkadot-sdk.git polkadot-sdk - - cd polkadot-sdk - - cargo build -p polkadot --release --features fast-runtime - - mkdir -p ~/.local/bin - - mv ./target/release/polkadot /usr/bin - - mv ./target/release/polkadot-execute-worker /usr/bin - - mv ./target/release/polkadot-prepare-worker /usr/bin - - polkadot --version - - cd - - - rm -rf polkadot - - cd staking-miner-playground - - cargo build --release --features test-trimming - - mv ./target/release/staking-miner-playground /usr/bin - - staking-miner-playground --version - - cd - - - RUST_LOG=info cargo test --workspace --all-features -- --nocapture - - cargo clean - after_script: - - echo $CI_JOB_STATUS > nightly_test_result - artifacts: - when: always - paths: - - nightly_test_result - -nightly-test-notification: - stage: nightly-test - image: paritytech/tools:latest - rules: - - if: $CI_PIPELINE_SOURCE == "schedule" - needs: ["nightly-test"] - when: always - script: - - \[ ! -f nightly_test_result \] && TEST_JOB_STATUS=failed || TEST_JOB_STATUS=$(" or tag - - if [[ $CI_COMMIT_REF_NAME == "main" ]]; - then - export VERSION=main-${CI_COMMIT_SHORT_SHA}; - else - export VERSION=$CI_COMMIT_REF_NAME; - fi - - test "$DOCKER_USER" -a "$DOCKER_PASS" || - ( echo "no docker credentials provided"; exit 1 ) - - cd ./artifacts - - $BUILDAH_COMMAND build - --format=docker - --build-arg VCS_REF="${CI_COMMIT_SHA}" - --build-arg BUILD_DATE="$(date -u '+%Y-%m-%dT%H:%M:%SZ')" - --build-arg IMAGE_NAME="${IMAGE_NAME}" - --tag "$IMAGE_NAME:latest" - --tag "$IMAGE_NAME:$VERSION" - --file Dockerfile . - # The job will success only on the protected branch - - echo "$DOCKER_PASS" | - buildah login --username "$DOCKER_USER" --password-stdin docker.io - - $BUILDAH_COMMAND info - - $BUILDAH_COMMAND push --format=v2s2 "$IMAGE_NAME:latest" - - $BUILDAH_COMMAND push --format=v2s2 "$IMAGE_NAME:$VERSION" - after_script: - - buildah logout --all - -publish-docker-image-description: - stage: publish - <<: *kubernetes-env - image: paritytech/dockerhub-description - variables: - DOCKER_USERNAME: $Docker_Hub_User_Parity - DOCKER_PASSWORD: $Docker_Hub_Pass_Parity - README_FILEPATH: $CI_PROJECT_DIR/Dockerfile.README.md - DOCKERHUB_REPOSITORY: paritytech/staking-miner-v2 - SHORT_DESCRIPTION: "staking-miner-v2" - rules: - - if: $CI_COMMIT_REF_NAME == "main" - changes: - - Dockerfile.README.md - script: - - cd / && sh entrypoint.sh diff --git a/Dockerfile b/Dockerfile index 632edb636..7991f484d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM docker.io/library/ubuntu:20.04 +FROM docker.io/library/ubuntu:22.04 # metadata ARG VCS_REF