-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate GitLab CI to GitHub Actions #729
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
762762e
Migrate GitLab CI to GitHub Actions
sergejparity eab2d66
staking-miner-v2 to polkadot-staking-miner
sergejparity 017430c
Update .github/workflows/ci.yml
sergejparity 14845fb
Merge main
sergejparity fdd964e
add environment
sergejparity 73b073b
fix docker login condition
sergejparity 3a9170c
apply suggestions and split test and prod docker image build
sergejparity 5227a2d
fix nightly naming
sergejparity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,262 @@ | ||
name: Polkadot Staking Miner CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
tags: | ||
- v* | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
env: | ||
IMAGE: paritytech/ci-unified:bullseye-1.74.0-2023-11-01-v20231204 | ||
IMAGE_NAME: paritytech/polkadot-staking-miner | ||
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 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 | ||
|
||
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, | ||
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: Set permissions | ||
run: chmod +x ./artifacts/polkadot-staking-miner | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Build Docker image | ||
uses: docker/build-push-action@v5 | ||
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/main' || github.ref_type == 'tag' }} | ||
runs-on: ubuntu-latest | ||
environment: main_and_tags | ||
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: | | ||
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 }}!" | ||
chmod +x ./artifacts/polkadot-staking-miner | ||
|
||
- name: Log in to Docker Hub | ||
if: ${{ github.ref == 'refs/heads/main' || 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@v5 | ||
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 |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sergejparity
Do think it would be easy to cache these binaries similar to what https://github.com/paritytech/subxt/blob/master/.github/workflows/build-substrate.yml does?
We might be able to enable this in the CI instead of running it every night then...
The staking-miner-playaround is rarely changed and it might be possible to cache and only rebuild it if the versions doesn't match...