From 8d42972db2250b6f5c9f6ec2dccfbe98d275e5e6 Mon Sep 17 00:00:00 2001 From: Alexander Samusev <41779041+alvicsam@users.noreply.github.com> Date: Wed, 25 Sep 2024 11:26:11 +0200 Subject: [PATCH] [ci] Move CI to GHA (#235) PR moves CI from Gitlab to GitHub. The release publish flow changed a bit: now tag should be pushed with the `-m` option. I added this change to Readme. @smiasojed since you were the last person who created latest releases I'm pinging you so you are aware of the changes. cc https://github.com/paritytech/ci_cd/issues/1040 --- .github/workflows/ci.yml | 166 +++++++++++++++++++++++ .github/workflows/gitspiegel-trigger.yml | 22 --- .gitlab-ci.yml | 165 ---------------------- README.md | 18 ++- 4 files changed, 178 insertions(+), 193 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .github/workflows/gitspiegel-trigger.yml delete mode 100644 .gitlab-ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..bb4e40c --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,166 @@ +name: CI + +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +# common variable is defined in the workflow +# repo env variable doesn't work for PR from forks +env: + CI_IMAGE: "paritytech/ci-unified:bullseye-1.75.0-2024-01-22-v20240222" + +jobs: + set-image: + # This workaround sets the container image for each job using 'set-image' job output. + # env variables don't work for PR from forks, so we need to use outputs. + runs-on: ubuntu-latest + outputs: + CI_IMAGE: ${{ steps.set_image.outputs.CI_IMAGE }} + steps: + - id: set_image + run: echo "CI_IMAGE=${{ env.CI_IMAGE }}" >> $GITHUB_OUTPUT + + fmt: + name: Cargo fmt + runs-on: ubuntu-latest + timeout-minutes: 5 + needs: [set-image] + container: + image: ${{ needs.set-image.outputs.CI_IMAGE }} + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - name: Rust Cache + uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + with: + cache-on-failure: true + cache-all-crates: true + - name: cargo info + run: | + echo "######## rustup show ########" + rustup show + echo "######## cargo --version ########" + cargo --version + - name: Cargo fmt + run: cargo +nightly fmt --all -- --check + + build-test-linux: + name: Build Linux + runs-on: parity-large + timeout-minutes: 50 + needs: [set-image, fmt] + container: + image: ${{ needs.set-image.outputs.CI_IMAGE }} + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - name: Rust Cache + uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + with: + cache-on-failure: true + cache-all-crates: true + - name: cargo info + run: | + echo "######## rustup show ########" + rustup show + echo "######## cargo --version ########" + cargo --version + - name: Build and Test Linux + run: | + echo "######## cargo build ########" + cargo build --release + echo "######## cargo test ########" + cargo test --release --all + echo "######## Packing artifacts ########" + mkdir -p ./artifacts/substrate-contracts-node-linux/ + cp target/release/substrate-contracts-node ./artifacts/substrate-contracts-node-linux/substrate-contracts-node + ls -la ./artifacts/substrate-contracts-node-linux/ + - name: Upload artifacts + uses: actions/upload-artifact@v4.3.6 + with: + name: build-linux + path: ./artifacts + build-macos: + timeout-minutes: 30 + runs-on: parity-macos + needs: [fmt] + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - name: Set rust version from env file + run: | + echo $CI_IMAGE + RUST_VERSION=$(echo $CI_IMAGE | sed -E 's/.*ci-unified:([^-]+)-([^-]+).*/\2/') + echo $RUST_VERSION + echo "RUST_VERSION=${RUST_VERSION}" >> $GITHUB_ENV + - name: Set up Homebrew + uses: Homebrew/actions/setup-homebrew@1ccc07ccd54b6048295516a3eb89b192c35057dc # master from 12.09.2024 + - name: Install protobuf + run: brew install protobuf + - name: Install rust ${{ env.RUST_VERSION }} + uses: actions-rust-lang/setup-rust-toolchain@1fbea72663f6d4c03efaab13560c8a24cfd2a7cc # v1.9.0 + with: + cache: false + toolchain: ${{ env.RUST_VERSION }} + target: wasm32-unknown-unknown, aarch64-apple-darwin, x86_64-apple-darwin + components: cargo, clippy, rust-docs, rust-src, rustfmt, rustc, rust-std + - name: cargo info + run: | + echo "######## rustup show ########" + rustup show + echo "######## cargo --version ########" + cargo --version + - name: Rust Cache + uses: Swatinem/rust-cache@23bce251a8cd2ffc3c1075eaa2367cf899916d84 # v2.7.3 + with: + cache-on-failure: true + cache-all-crates: true + - name: Run cargo build + run: | + echo "######## cargo build aarch64-apple-darwin ########" + cargo build --release --target aarch64-apple-darwin + echo "######## cargo build x86_64-apple-darwin ########" + cargo build --release --target x86_64-apple-darwin + echo "######## Packing artifacts ########" + mkdir -p ./artifacts/substrate-contracts-node-mac/ + lipo ./target/x86_64-apple-darwin/release/substrate-contracts-node \ + ./target/aarch64-apple-darwin/release/substrate-contracts-node \ + -create -output ./artifacts/substrate-contracts-node-mac/substrate-contracts-node + ls -la ./artifacts/substrate-contracts-node-mac/ + - name: Upload artifacts + uses: actions/upload-artifact@v4.3.6 + with: + name: build-macos + path: ./artifacts + publish: + name: Publish release + runs-on: ubuntu-latest + needs: [build-test-linux, build-macos] + permissions: + contents: write + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 + - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 + with: + name: build-linux + - uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8 + with: + name: build-macos + - name: Pack artifacts + run: | + tar -czvf ./substrate-contracts-node-linux.tar.gz ./substrate-contracts-node-linux + tar -czvf ./substrate-contracts-node-mac-universal.tar.gz ./substrate-contracts-node-mac + ls -la + - name: Publish release + uses: ghalactic/github-release-from-tag@cebdacac0ccd08933b8e7f278f4123723ad978eb # v5.4.0 + if: github.ref_type == 'tag' + with: + prerelease: false + draft: true + assets: | + - path: substrate-contracts-node-linux.tar.gz + - path: substrate-contracts-node-mac-universal.tar.gz diff --git a/.github/workflows/gitspiegel-trigger.yml b/.github/workflows/gitspiegel-trigger.yml deleted file mode 100644 index dce3aaf..0000000 --- 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/.gitlab-ci.yml b/.gitlab-ci.yml deleted file mode 100644 index 2bfc1ef..0000000 --- a/.gitlab-ci.yml +++ /dev/null @@ -1,165 +0,0 @@ -# .gitlab-ci.yml -# -# substrate-contracts-node -# -# pipelines can be triggered manually in the web - -default: - interruptible: true - retry: - max: 2 - when: - - runner_system_failure - - unknown_failure - - api_failure - -stages: - - fmt - - build-linux - - build-mac - - publish - -variables: - GIT_STRATEGY: fetch - GIT_DEPTH: 100 - CARGO_INCREMENTAL: 0 - -.collect-artifacts: &collect-artifacts - artifacts: - name: "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}" - when: on_success - expire_in: 7 days - paths: - - artifacts/ - -.docker-env: &docker-env - image: paritytech/ci-unified:latest - before_script: - - cargo -vV - - rustc -vV - - rustup show - - bash --version - tags: - - linux-docker-vm-c2 - -.kubernetes-env: &kubernetes-env - tags: - - kubernetes-parity-build - -.build-refs: &build-refs - rules: - - if: $CI_PIPELINE_SOURCE == "schedule" - - if: $CI_COMMIT_REF_NAME == "main" - - if: $CI_COMMIT_REF_NAME == "tags" - - 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" - - if: $CI_COMMIT_REF_NAME =~ /^v[0-9]+\.[0-9]+.*$/ # i.e. v1.0, v2.1rc1 - -### stage: fmt - -fmt: - stage: fmt - <<: *docker-env - script: - - cargo +nightly fmt --verbose --all -- --check - -### stage: build-linux - -build-linux: - stage: build-linux - <<: *docker-env - <<: *collect-artifacts - <<: *build-refs - script: - - time cargo build --release - - time cargo test --release --all - - mkdir -p ./artifacts/substrate-contracts-node-linux/ - - cp target/release/substrate-contracts-node ./artifacts/substrate-contracts-node-linux/substrate-contracts-node - -### stage: build-mac - -build-mac: - stage: build-mac - <<: *docker-env - <<: *collect-artifacts - <<: *build-refs - before_script: - - unset CARGO_TARGET_DIR - script: - - rustup component add rust-src rustfmt - - rustup target add wasm32-unknown-unknown aarch64-apple-darwin - - time cargo build --release --target aarch64-apple-darwin - - rustup target add x86_64-apple-darwin - - time cargo build --release --target x86_64-apple-darwin - - mkdir -p ./artifacts/substrate-contracts-node-mac/ - - 'lipo - ./target/x86_64-apple-darwin/release/substrate-contracts-node - ./target/aarch64-apple-darwin/release/substrate-contracts-node - -create - -output ./artifacts/substrate-contracts-node-mac/substrate-contracts-node' - tags: - - osx - -publish: - stage: publish - <<: *kubernetes-env - image: paritytech/tools:latest - <<: *publish-refs - needs: - - job: build-linux - artifacts: true - - job: build-mac - artifacts: true - script: - - git describe --tags - - TAG_NAME=`git describe --tags` - - echo "tag name ${TAG_NAME}" - - tar -czvf ./substrate-contracts-node-linux.tar.gz ./artifacts/substrate-contracts-node-linux/substrate-contracts-node - - tar -czvf ./substrate-contracts-node-mac-universal.tar.gz ./artifacts/substrate-contracts-node-mac/substrate-contracts-node - - 'curl https://api.github.com/repos/paritytech/substrate-contracts-node/releases - --fail-with-body - -H "Cookie: logged_in=no" - -H "Authorization: token ${GITHUB_TOKEN}"' - - 'curl https://api.github.com/repos/paritytech/substrate-contracts-node/releases - --fail-with-body - -H "Cookie: logged_in=no" - -H "Authorization: token ${GITHUB_TOKEN}" | jq .' - - 'RELEASE_ID=$(curl https://api.github.com/repos/paritytech/substrate-contracts-node/releases - --fail-with-body - -H "Cookie: logged_in=no" - -H "Authorization: token ${GITHUB_TOKEN}" - | jq -r ".[] | select(.tag_name == \"$TAG_NAME\") | .id"); - echo "release id if existent: ${RELEASE_ID}"' - - 'if [ -z "$RELEASE_ID" ]; then - RESP=$(curl -X "POST" "https://api.github.com/repos/paritytech/substrate-contracts-node/releases" - --fail-with-body - -H "Cookie: logged_in=no" - -H "Authorization: token ${GITHUB_TOKEN}" - -H "Content-Type: application/json; charset=utf-8" - -d $"{ - \"tag_name\": \"${TAG_NAME}\", - \"name\": \"${TAG_NAME}\", - \"prerelease\": false, - \"draft\": true - }"); - echo "api response ${RESP}"; - RELEASE_ID=$(echo $RESP | jq -r .id); - echo "release id of created release ${RELEASE_ID}"; - fi' - - echo "release id ${RELEASE_ID}" - - 'curl -X "POST" "https://uploads.github.com/repos/paritytech/substrate-contracts-node/releases/$RELEASE_ID/assets?name=substrate-contracts-node-linux.tar.gz" - --fail-with-body - -H "Cookie: logged_in=no" - -H "Authorization: token ${GITHUB_TOKEN}" - -H "Content-Type: application/octet-stream" - --data-binary @"./substrate-contracts-node-linux.tar.gz"' - - 'curl -X "POST" "https://uploads.github.com/repos/paritytech/substrate-contracts-node/releases/$RELEASE_ID/assets?name=substrate-contracts-node-mac-universal.tar.gz" - --fail-with-body - -H "Cookie: logged_in=no" - -H "Authorization: token ${GITHUB_TOKEN}" - -H "Content-Type: application/octet-stream" - --data-binary @"./substrate-contracts-node-mac-universal.tar.gz"' diff --git a/README.md b/README.md index d366a05..ef3e9f7 100644 --- a/README.md +++ b/README.md @@ -109,12 +109,18 @@ We can have two types of releases: `cargo release 0.XX.0 -v --no-tag --no-push -p contracts-node --execute` Note: Before uploading, perform a dry run to ensure that it will be successful. - [ ] Merge the release PR branch. -- [ ] Replace `XX` in this command with your incremented version number and execute it: - `git checkout main && git pull && git tag v0.XX.0 && git push origin v0.XX.0`. - This will push a new tag with the version number to this repository. -- [ ] We have set this repository up in a way that tags à la `vX.X.X` trigger - a CI run that creates a GitHub draft release. You can observe CI runs on - [GitLab](https://gitlab.parity.io/parity/mirrors/substrate-contracts-node/-/pipelines). +- [ ] Set the tag and run the following commands to push the tag. The tag must contain a message, otherwise the github action won't be able to create a release: + +```bash +TAG="v0.XX.0" +git checkout main +git pull +git tag -a ${TAG} -m "${TAG}" +git push origin ${TAG} +``` + + +- [ ] After tag is pushed CI creates a GitHub draft release. This draft release will contain a binary for Linux and Mac and appear under [Releases](https://github.com/paritytech/substrate-contracts-node/releases). Add a description in the style of "Synchronized with [`polkadot-v1.8.0`](https://github.com/paritytech/polkadot-sdk/tree/release-polkadot-v1.8.0) branch."