diff --git a/.github/ci/macos-install-packages b/.github/ci/macos-install-packages new file mode 100755 index 0000000..afb1102 --- /dev/null +++ b/.github/ci/macos-install-packages @@ -0,0 +1,6 @@ +#!/bin/sh + +brew install asciidoctor + +brew install openssl@1.1 +cp /usr/local/opt/openssl@1.1/lib/pkgconfig/*.pc /usr/local/lib/pkgconfig/ diff --git a/.github/ci/ubuntu-install-packages b/.github/ci/ubuntu-install-packages new file mode 100755 index 0000000..6ef648b --- /dev/null +++ b/.github/ci/ubuntu-install-packages @@ -0,0 +1,6 @@ +#!/bin/sh + +sudo apt-get update +sudo apt-get install -y --no-install-recommends \ + asciidoctor \ + zsh xz-utils liblz4-tool musl-tools libssl-dev openssl pkg-config diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..3dada2d --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,104 @@ +on: [push, pull_request] + +name: Build + +jobs: + check: + name: Check + runs-on: ubuntu-latest + strategy: + matrix: + rust: + - stable + - 1.55.0 + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + override: true + + - name: Run cargo check + uses: actions-rs/cargo@v1 + with: + command: check + + test: + name: Test Suite + runs-on: ubuntu-latest + strategy: + matrix: + rust: + - stable + - 1.55.0 + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + override: true + + - name: Run cargo test + uses: actions-rs/cargo@v1 + with: + command: test + + fmt: + name: Rustfmt + runs-on: ubuntu-latest + strategy: + matrix: + rust: + - stable + - 1.55.0 + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + override: true + + - name: Install rustfmt + run: rustup component add rustfmt + + - name: Run cargo fmt + uses: actions-rs/cargo@v1 + with: + command: fmt + args: --all -- --check + + clippy: + name: Clippy + runs-on: ubuntu-latest + strategy: + matrix: + rust: + - stable + - 1.55.0 + steps: + - name: Checkout sources + uses: actions/checkout@v2 + + - name: Install toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + override: true + + - name: Install clippy + run: rustup component add clippy + + - name: Run cargo clippy + uses: actions-rs/cargo@v1 + with: + command: clippy + args: -- -D warnings diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..31848d9 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,122 @@ +name: release +on: + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' +jobs: + create-release: + name: create-release + runs-on: ubuntu-latest + steps: + - name: Create artifacts directory + run: mkdir artifacts + + - name: Get the release version from the tag + if: env.VERSION == '' + run: | + echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + echo "version is: ${{ env.VERSION }}" + - name: Create GitHub release + id: release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ env.VERSION }} + release_name: ${{ env.VERSION }} + + - name: Save release upload URL to artifact + run: echo "${{ steps.release.outputs.upload_url }}" > artifacts/release-upload-url + + - name: Save version number to artifact + run: echo "${{ env.VERSION }}" > artifacts/release-version + + - name: Upload artifacts + uses: actions/upload-artifact@v1 + with: + name: artifacts + path: artifacts + + build-release: + name: build-release + needs: [ 'create-release' ] + runs-on: ${{ matrix.os }} + env: + # Emit backtraces on panics. + RUST_BACKTRACE: 1 + strategy: + matrix: + build: [ linux-amd64, macos-intel, windows ] + include: + - build: linux-amd64 + os: ubuntu-18.04 + rust: stable + target: x86_64-unknown-linux-musl + - build: macos-intel + os: macos-latest + rust: stable + target: x86_64-apple-darwin + - build: windows + os: windows-2019 + rust: stable + target: x86_64-pc-windows-msvc + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + with: + fetch-depth: 1 + + - name: Install packages (Ubuntu) + if: matrix.os == 'ubuntu-18.04' + run: | + .github/ci/ubuntu-install-packages + - name: Install packages (macOS) + if: matrix.os == 'macos-latest' + run: | + .github/ci/macos-install-packages + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + profile: minimal + override: true + target: ${{ matrix.target }} + + - name: Get release download URL + uses: actions/download-artifact@v1 + with: + name: artifacts + path: artifacts + + - name: Set release upload URL + shell: bash + run: | + release_upload_url="$(cat artifacts/release-upload-url)" + echo "RELEASE_UPLOAD_URL=$release_upload_url" >> $GITHUB_ENV + echo "release upload url: $release_upload_url" + + - name: Build onetun binary + run: cargo build --release + + - name: Prepare onetun binary + shell: bash + run: | + mkdir -p ci/assets + if [ "${{ matrix.build }}" = "windows" ]; then + cp "target/release/onetun.exe" "ci/assets/onetun.exe" + echo "ASSET=onetun.exe" >> $GITHUB_ENV + else + cp "target/release/onetun" "ci/assets/onetun-${{ matrix.build }}" + echo "ASSET=onetun-${{ matrix.build }}" >> $GITHUB_ENV + fi + + - name: Upload release archive + uses: actions/upload-release-asset@v1.0.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ env.RELEASE_UPLOAD_URL }} + asset_path: ci/assets/${{ env.ASSET }} + asset_name: ${{ env.ASSET }} + asset_content_type: application/octet-stream