From 0e8c10e4b3272a52cddb3b9894b37ac6108534a3 Mon Sep 17 00:00:00 2001 From: Bao Zhiyuan Date: Fri, 5 Jul 2024 16:24:48 +0800 Subject: [PATCH] add pipeline --- .github/workflows/cd.yml | 132 +++++++++++++++++ .github/workflows/ci.yml | 231 +++++++++++++++++++++++++++++ .github/workflows/test-on-main.yml | 149 +++++++++++++++++++ 3 files changed, 512 insertions(+) create mode 100644 .github/workflows/cd.yml create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/test-on-main.yml diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 00000000..67e951c8 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,132 @@ +# Copyright 2024 International Digital Economy Academy +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +name: CD + +on: + workflow_dispatch: + push: + branches: + - main + +jobs: + build: + strategy: + matrix: + os: [macos-latest, macos-13, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@1.77.0 + - name: Cargo cache + uses: actions/cache@v4 + with: + key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }} + path: ~/.cargo/registry + - name: Build + run: cargo build --release + + - name: Setup Rclone + uses: AnimMouse/setup-rclone@v1 + with: + rclone_config: ${{ secrets.RCLONE_CONFIG }} + + - name: Upload(Unix) + if: ${{ matrix.os != 'windows-latest' }} + run: | + version=$(echo "$GITHUB_SHA" | cut -c 1-9) + rclone copy target/release/moon "aws:${{ secrets.AWS_BUCKET_NAME }}/bleeding-moon/$version/$(uname -s)-$(uname -m)/" + + - name: Upload(Windows) + if: ${{ matrix.os == 'windows-latest' }} + run: | + $version = "$env:GITHUB_SHA".Substring(0, 9) + rclone copyto -L .\target\release\moon.exe "aws:${{ secrets.AWS_BUCKET_NAME }}/bleeding-moon/$version/Windows-x86_64/moon.exe" + + - name: Checkout moonc-version (macos-latest) + if: ${{ matrix.os == 'macos-latest' }} + uses: actions/checkout@v4 + with: + ref: moonc-version-dont-delete + path: moonc-version-dont-delete + + - name: Copy moonc-version file to workspace (macos-latest) + if: ${{ matrix.os == 'macos-latest' }} + run: | + cp moonc-version-dont-delete/moonc-version . + + - name: Bleeding Release (macos-latest) + if: ${{ matrix.os == 'macos-latest' }} + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }} + run: | + rm -rf tmp-bins + mkdir tmp-bins + mooncVersion=$(cat moonc-version | cut -c 1-9) + rclone copy "aws:${{ secrets.AWS_BUCKET_NAME }}/bleeding-moonc/$mooncVersion/$(uname -s)-$(uname -m)/" ./tmp-bins/ + moonrunVersion=33bbc3ed9 + rclone copy "aws:${{ secrets.AWS_BUCKET_NAME }}/bleeding-moonrun/$moonrunVersion/$(uname -s)-$(uname -m)/moonrun" ./tmp-bins/ + cp -L ./target/release/moon ./tmp-bins/ + pushd tmp-bins && shasum -a 256 -- * >../moonbit-darwin-aarch64.sha256 && popd + tar czf ./moonbit-darwin-aarch64.tar.gz --directory=./tmp-bins . + aws s3 cp ./moonbit-darwin-aarch64.tar.gz s3://cli.moonbitlang.com/binaries/bleeding/moonbit-darwin-aarch64.tar.gz + aws s3 cp ./moonbit-darwin-aarch64.sha256 s3://cli.moonbitlang.com/binaries/bleeding/moonbit-darwin-aarch64.sha256 + aws cloudfront create-invalidation --distribution-id E1KQYZEVEB0TAY --paths "/*" + + ubuntu-build: + runs-on: ubuntu-latest + container: + image: ubuntu:16.04 + steps: + - name: Install dependencies + run: | + apt update && apt install -y software-properties-common curl unzip build-essential git + + - name: Checkout + run: | + git clone --depth 1 "https://${{ secrets.MOON_CLONE_PAT }}@github.com/moonbitlang/moon.git" "$GITHUB_WORKSPACE" + + - name: Install Rust + run: | + curl --proto '=https' --tlsv1.2 -sSf "https://sh.rustup.rs" | sh -s -- -y + echo ~/.cargo/bin >> $GITHUB_PATH + + - name: Rust Version + run: | + cargo version + rustc --version + + - run: | + git config --global --add safe.directory "$(pwd)" + git status + + - name: Build + run: cargo build --release + + - name: Setup Rclone + env: + RCLONE_CONFIG_PLAIN: ${{ secrets.RCLONE_CONFIG_PLAIN }} + run: | + curl https://rclone.org/install.sh | bash + mkdir -p ~/.config/rclone + echo "$RCLONE_CONFIG_PLAIN" > ~/.config/rclone/rclone.conf + + - name: Upload + run: | + version="$(echo "$GITHUB_SHA" | cut -c 1-9)" + echo "$version" + rclone copy target/release/moon "aws:${{ secrets.AWS_BUCKET_NAME }}/bleeding-moon/$version/$(uname -s)-$(uname -m)/" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..e83c7b83 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,231 @@ +# Copyright 2024 International Digital Economy Academy +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +name: CI + +on: + # push: + # branches: main + pull_request: + branches: main + +env: + CARGO_TERM_COLOR: always + RUST_BACKTRACE: 0 + CARGO_TARPAULIN_VERSION: 0.30.0 + +jobs: + license-header-check: + name: license header check + runs-on: ubuntu-latest + env: + HAWKEYE_VERSION: v5.6.0 + steps: + - uses: actions/checkout@v4 + - name: Download HawkEye + run: curl --proto '=https' --tlsv1.2 -LsSf https://github.com/korandoru/hawkeye/releases/download/$HAWKEYE_VERSION/hawkeye-installer.sh | sh + - name: License Header Check + run: hawkeye check + + typo-check: + name: typo-check + runs-on: ubuntu-latest + timeout-minutes: 10 + env: + FORCE_COLOR: 1 + TYPOS_VERSION: v1.18.0 + steps: + - name: download typos + run: curl -LsSf https://github.com/crate-ci/typos/releases/download/$TYPOS_VERSION/typos-$TYPOS_VERSION-x86_64-unknown-linux-musl.tar.gz | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin + - name: Checkout repository + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.sha }} + - name: check for typos + run: typos + + code-style: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@1.77.0 + with: + components: rustfmt, clippy + - name: Check formatting + run: cargo fmt -- --check + - name: Clippy + run: cargo clippy --all-targets --all-features -- -D warnings + + test: + needs: [code-style, typo-check, license-header-check] + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + # - macos-latest + # - macos-13 + - windows-latest + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + + - name: Checkout moonc-version + uses: actions/checkout@v4 + with: + ref: moonc-version-dont-delete + path: moonc-version-dont-delete + - name: Copy moonc-version file to workspace + run: | + cp moonc-version-dont-delete/moonc-version . + + - uses: dtolnay/rust-toolchain@1.77.0 + - name: Cargo cache + uses: actions/cache@v4 + with: + key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }} + path: ~/.cargo/registry + + - name: Setup Rclone + uses: AnimMouse/setup-rclone@v1 + with: + rclone_config: ${{ secrets.RCLONE_CONFIG }} + + - name: install MoonBit(Unix) + if: ${{ matrix.os != 'windows-latest' }} + run: | + mkdir -p ~/.moon/bin + mkdir -p ~/.moon/lib + git clone --depth 1 https://github.com/moonbitlang/core.git ~/.moon/lib/core + mooncVersion=$(cat moonc-version | cut -c 1-9) + echo "$mooncVersion" + bins=('moonc' 'mooninfo' 'moonfmt') + for bin in "${bins[@]}"; do + rclone copy "aws:${{ secrets.AWS_BUCKET_NAME }}/bleeding-moonc/$mooncVersion/$(uname -s)-$(uname -m)/$bin" ~/.moon/bin/ + chmod +x ~/.moon/bin/"$bin" + done + moonrunVersion=33bbc3ed9 + rclone copy "aws:${{ secrets.AWS_BUCKET_NAME }}/bleeding-moonrun/$moonrunVersion/$(uname -s)-$(uname -m)/moonrun" ~/.moon/bin/ + chmod +x ~/.moon/bin/moonrun + echo "$HOME/.moon/bin" >> $GITHUB_PATH + + - name: install MoonBit(Windows) + if: ${{ matrix.os == 'windows-latest' }} + run: | + New-Item -Path "$env:USERPROFILE" -Name ".moon" -ItemType "directory" + New-Item -Path "$env:USERPROFILE\.moon" -Name "lib" -ItemType "directory" + New-Item -Path "$env:USERPROFILE\.moon" -Name "bin" -ItemType "directory" + $mooncVersion = (Get-Content moonc-version -First 1).Substring(0, 9) + $bins = @("moonc.exe", "mooninfo.exe", "moonfmt.exe") + foreach ($bin in $bins) { + rclone copy "aws:${{ secrets.AWS_BUCKET_NAME }}/bleeding-moonc/$mooncVersion/Windows-x86_64/$bin" "$env:USERPROFILE\.moon\bin\" + } + $moonrunVersion = "33bbc3ed9" + rclone copy "aws:${{ secrets.AWS_BUCKET_NAME }}/bleeding-moonrun/$moonrunVersion/Windows-x86_64/moonrun.exe" "$env:USERPROFILE\.moon\bin\" + git clone --depth 1 https://github.com/moonbitlang/core.git "$env:USERPROFILE\.moon\lib\core" + "$env:USERPROFILE\.moon\bin" | Out-File -FilePath $env:GITHUB_PATH -Append + + - name: Build + run: cargo build + - name: Versions + run: cargo run --bin moon version --all + - name: Bundle core (Unix) + if: ${{ matrix.os != 'windows-latest' }} + run: cargo run --bin moon bundle --source-dir ~/.moon/lib/core --all + - name: Bundle core (Windows) + if: ${{ matrix.os == 'windows-latest' }} + run: cargo run --bin moon bundle --source-dir "$env:USERPROFILE\.moon\lib\core" --all + + - name: Test core (Unix) + if: ${{ matrix.os != 'windows-latest' }} + run: | + cargo run --bin moon test --source-dir ~/.moon/lib/core --target wasm-gc + cargo run --bin moon test --source-dir ~/.moon/lib/core --target js + cargo run --bin moon test --source-dir ~/.moon/lib/core --target wasm + cargo run --bin moon test --source-dir ~/.moon/lib/core --release --target wasm-gc + cargo run --bin moon test --source-dir ~/.moon/lib/core --release --target js + cargo run --bin moon test --source-dir ~/.moon/lib/core --release --target wasm + - name: Test core (Windows) + if: ${{ matrix.os == 'windows-latest' }} + run: | + cargo run --bin moon test --source-dir "$env:USERPROFILE\.moon\lib\core" --target wasm-gc + cargo run --bin moon test --source-dir "$env:USERPROFILE\.moon\lib\core" --target js + cargo run --bin moon test --source-dir "$env:USERPROFILE\.moon\lib\core" --target wasm + cargo run --bin moon test --source-dir "$env:USERPROFILE\.moon\lib\core" --release --target wasm-gc + cargo run --bin moon test --source-dir "$env:USERPROFILE\.moon\lib\core" --release --target js + cargo run --bin moon test --source-dir "$env:USERPROFILE\.moon\lib\core" --release --target wasm + + - name: Run tests + run: cargo test + + coverage: + needs: test + runs-on: macos-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@1.77.0 + + - name: Checkout moonc-version + uses: actions/checkout@v4 + with: + ref: moonc-version-dont-delete + path: moonc-version-dont-delete + - name: Copy moonc-version file to workspace + run: | + cp moonc-version-dont-delete/moonc-version . + + - name: Setup Rclone + uses: AnimMouse/setup-rclone@v1 + with: + rclone_config: ${{ secrets.RCLONE_CONFIG }} + + - name: install MoonBit(Unix) + run: | + mkdir -p ~/.moon/bin + mkdir -p ~/.moon/lib + git clone --depth 1 https://github.com/moonbitlang/core.git ~/.moon/lib/core + mooncVersion=$(cat moonc-version | cut -c 1-9) + echo "$mooncVersion" + bins=('moonc' 'mooninfo' 'moonfmt') + for bin in "${bins[@]}"; do + rclone copy "aws:${{ secrets.AWS_BUCKET_NAME }}/bleeding-moonc/$mooncVersion/$(uname -s)-$(uname -m)/$bin" ~/.moon/bin/ + chmod +x ~/.moon/bin/"$bin" + done + moonrunVersion=33bbc3ed9 + rclone copy "aws:${{ secrets.AWS_BUCKET_NAME }}/bleeding-moonrun/$moonrunVersion/$(uname -s)-$(uname -m)/moonrun" ~/.moon/bin/ + chmod +x ~/.moon/bin/moonrun + echo "$HOME/.moon/bin" >> $GITHUB_PATH + + - name: install cargo-tarpaulin ${{ env.CARGO_TARPAULIN_VERSION }} + run: | + cd "${CARGO_HOME}/bin" + curl -sL https://github.com/xd009642/tarpaulin/releases/download/${CARGO_TARPAULIN_VERSION}/cargo-tarpaulin-aarch64-apple-darwin.tar.gz | tar zxf - -C ${CARGO_HOME:-~/.cargo}/bin + + - name: Build + run: cargo build + - name: Versions + run: cargo run --bin moon version --all + - name: Bundle core (Unix) + run: cargo run --bin moon bundle --source-dir ~/.moon/lib/core --all + + - name: Generate code coverage + run: cargo tarpaulin --ignore-tests --out Xml + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v4.0.1 + with: + token: ${{secrets.CODECOV_TOKEN}} + fail_ci_if_error: true diff --git a/.github/workflows/test-on-main.yml b/.github/workflows/test-on-main.yml new file mode 100644 index 00000000..820b253e --- /dev/null +++ b/.github/workflows/test-on-main.yml @@ -0,0 +1,149 @@ +# Copyright 2024 International Digital Economy Academy +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +name: Test on main + +on: + workflow_dispatch: + +jobs: + test: + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + # - macos-latest + # - macos-13 + - windows-latest + runs-on: ${{ matrix.os }} + env: + WECOM_ROBOT_KEY: ${{ secrets.WECOM_ROBOT_KEY }} + steps: + - uses: actions/checkout@v4 + + - name: Checkout moonc-version + uses: actions/checkout@v4 + with: + ref: moonc-version-dont-delete + path: moonc-version-dont-delete + - name: Copy moonc-version file to workspace + run: | + cp moonc-version-dont-delete/moonc-version . + + - uses: dtolnay/rust-toolchain@1.77.0 + - name: Cargo cache + uses: actions/cache@v4 + with: + key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }} + path: ~/.cargo/registry + + - name: Setup Rclone + uses: AnimMouse/setup-rclone@v1 + with: + rclone_config: ${{ secrets.RCLONE_CONFIG }} + + - name: install MoonBit(Unix) + if: ${{ matrix.os != 'windows-latest' }} + run: | + mkdir -p ~/.moon/bin + mkdir -p ~/.moon/lib + git clone --depth 1 https://github.com/moonbitlang/core.git ~/.moon/lib/core + mooncVersion=$(cat moonc-version | cut -c 1-9) + echo "$mooncVersion" + bins=('moonc' 'mooninfo' 'moonfmt') + for bin in "${bins[@]}"; do + rclone copy "aws:${{ secrets.AWS_BUCKET_NAME }}/bleeding-moonc/$mooncVersion/$(uname -s)-$(uname -m)/$bin" ~/.moon/bin/ + chmod +x ~/.moon/bin/"$bin" + done + moonrunVersion=33bbc3ed9 + rclone copy "aws:${{ secrets.AWS_BUCKET_NAME }}/bleeding-moonrun/$moonrunVersion/$(uname -s)-$(uname -m)/moonrun" ~/.moon/bin/ + chmod +x ~/.moon/bin/moonrun + echo "$HOME/.moon/bin" >> $GITHUB_PATH + + - name: install MoonBit(Windows) + if: ${{ matrix.os == 'windows-latest' }} + run: | + New-Item -Path "$env:USERPROFILE" -Name ".moon" -ItemType "directory" + New-Item -Path "$env:USERPROFILE\.moon" -Name "lib" -ItemType "directory" + New-Item -Path "$env:USERPROFILE\.moon" -Name "bin" -ItemType "directory" + $mooncVersion = (Get-Content moonc-version -First 1).Substring(0, 9) + $bins = @("moonc.exe", "mooninfo.exe", "moonfmt.exe") + foreach ($bin in $bins) { + rclone copy "aws:${{ secrets.AWS_BUCKET_NAME }}/bleeding-moonc/$mooncVersion/Windows-x86_64/$bin" "$env:USERPROFILE\.moon\bin\" + } + $moonrunVersion = "33bbc3ed9" + rclone copy "aws:${{ secrets.AWS_BUCKET_NAME }}/bleeding-moonrun/$moonrunVersion/Windows-x86_64/moonrun.exe" "$env:USERPROFILE\.moon\bin\" + git clone --depth 1 https://github.com/moonbitlang/core.git "$env:USERPROFILE\.moon\lib\core" + "$env:USERPROFILE\.moon\bin" | Out-File -FilePath $env:GITHUB_PATH -Append + + - name: Build + run: cargo build + - name: Versions + run: cargo run --bin moon version --all + - name: Bundle core (Unix) + if: ${{ matrix.os != 'windows-latest' }} + run: cargo run --bin moon bundle --source-dir ~/.moon/lib/core --all + - name: Bundle core (Windows) + if: ${{ matrix.os == 'windows-latest' }} + run: cargo run --bin moon bundle --source-dir "$env:USERPROFILE\.moon\lib\core" --all + + - name: Test core (Unix) + if: ${{ matrix.os != 'windows-latest' }} + run: | + cargo run --bin moon test --source-dir ~/.moon/lib/core --target wasm-gc + cargo run --bin moon test --source-dir ~/.moon/lib/core --target js + cargo run --bin moon test --source-dir ~/.moon/lib/core --target wasm + cargo run --bin moon test --source-dir ~/.moon/lib/core --release --target wasm-gc + cargo run --bin moon test --source-dir ~/.moon/lib/core --release --target js + cargo run --bin moon test --source-dir ~/.moon/lib/core --release --target wasm + - name: Test core (Windows) + if: ${{ matrix.os == 'windows-latest' }} + run: | + cargo run --bin moon test --source-dir "$env:USERPROFILE\.moon\lib\core" --target wasm-gc + cargo run --bin moon test --source-dir "$env:USERPROFILE\.moon\lib\core" --target js + cargo run --bin moon test --source-dir "$env:USERPROFILE\.moon\lib\core" --target wasm + cargo run --bin moon test --source-dir "$env:USERPROFILE\.moon\lib\core" --release --target wasm-gc + cargo run --bin moon test --source-dir "$env:USERPROFILE\.moon\lib\core" --release --target js + cargo run --bin moon test --source-dir "$env:USERPROFILE\.moon\lib\core" --release --target wasm + + - name: Run tests + run: cargo test + + - name: Notify on fail (windows) + if: ${{ failure() && matrix.os == 'windows-latest' }} + run: | + $body = @{ + msgtype = "text" + text = @{ + content = "🤣 moon ci on windows-latest failed: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{github.run_id}}" + } + } | ConvertTo-Json + + Invoke-RestMethod -Uri "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=$env:WECOM_ROBOT_KEY" -Method Post -ContentType "application/json" -Body $body + + - name: notify on fail (unix) + if: ${{ failure() && matrix.os != 'windows-latest' }} + run: | + curl "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=$WECOM_ROBOT_KEY" \ + -H 'Content-Type: application/json' \ + -d @- <