name: Nightly release on: workflow_dispatch: schedule: - cron: '0 0 * * *' defaults: run: shell: bash jobs: test: name: Test runs-on: ubuntu-latest-16-cores steps: - name: Install stable toolchain uses: dtolnay/rust-toolchain@stable with: toolchain: 1.71.1 - name: Checkout sources uses: actions/checkout@v3 - name: Setup cache uses: Swatinem/rust-cache@v2 with: save-if: ${{ github.ref == 'refs/heads/main' }} - name: Install dependencies run: | sudo apt-get -y update - name: Free up some disk space run: | (set -x; df -h) # Free up some disk space by removing unused files (set -x; sudo rm -rf /imagegeneration || true) (set -x; sudo rm -rf /opt/az || true) (set -x; sudo rm -rf /opt/hostedtoolcache || true) (set -x; sudo rm -rf /opt/google || true) (set -x; sudo rm -rf /opt/pipx || true) (set -x; df -h) - name: Install cargo-llvm-cov uses: taiki-e/install-action@cargo-llvm-cov - name: Install cargo-make run: cargo install --debug --locked cargo-make - name: Test workspace + coverage run: cargo make ci-workspace-coverage - name: Debug info if: always() run: | set -x free -m df -h ps auxf cat /tmp/surrealdb.log || true - name: Upload coverage report uses: actions/upload-artifact@v3 with: name: code-coverage-report path: target/llvm-cov/html/ retention-days: 5 lint: name: Lint runs-on: ubuntu-latest-16-cores steps: - name: Checkout sources uses: actions/checkout@v3 - name: Install dependencies run: | sudo apt-get -y update - name: Install stable toolchain uses: dtolnay/rust-toolchain@stable with: toolchain: 1.71.1 targets: wasm32-unknown-unknown components: rustfmt, clippy - name: Install cargo-make run: cargo install --debug --locked cargo-make - name: Check workspace run: cargo make ci-check - name: Check format run: cargo make ci-format - name: Check wasm run: cargo make ci-check-wasm - name: Check clippy run: cargo make ci-clippy build: name: Build ${{ matrix.arch }} needs: [test, lint] strategy: fail-fast: false matrix: include: - arch: x86_64-apple-darwin os: macos-latest-xl file: surreal-nightly.darwin-amd64 opts: --features storage-tikv,http-compression - arch: aarch64-apple-darwin os: macos-latest-xl file: surreal-nightly.darwin-arm64 opts: --features storage-tikv,http-compression - arch: x86_64-unknown-linux-gnu os: ubuntu-latest-16-cores file: surreal-nightly.linux-amd64 opts: --features storage-tikv,http-compression - arch: aarch64-unknown-linux-gnu os: ubuntu-latest-16-cores file: surreal-nightly.linux-arm64 opts: --features storage-tikv,http-compression - arch: x86_64-pc-windows-msvc os: windows-latest file: surreal-nightly.windows-amd64 opts: runs-on: ${{ matrix.os }} steps: - name: Checkout sources uses: actions/checkout@v3 - name: Prepare environment if: contains(matrix.arch, 'windows') && endsWith(matrix.arch, '-gnu') run: echo "C:\msys64\usr\bin;$Env:Path" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 - name: Install dependencies if: contains(matrix.arch, 'windows') && endsWith(matrix.arch, '-msvc') run: | vcpkg integrate install - name: Install dependencies if: contains(matrix.arch, 'apple') && endsWith(matrix.arch, '-darwin') run: | brew install protobuf - name: Install dependencies if: contains(matrix.arch, 'linux') && endsWith(matrix.arch, '-gnu') run: | sudo apt-get -y update sudo apt-get -y install musl-tools qemu-user libc6-dev-arm64-cross sudo apt-get -y install g++-aarch64-linux-gnu gcc-aarch64-linux-gnu - name: Install FoundationDB if: contains(matrix.arch, 'linux') && startsWith(matrix.arch, 'x86_64') run: | curl -sLO https://github.com/apple/foundationdb/releases/download/6.3.23/foundationdb-clients_6.3.23-1_amd64.deb sudo dpkg -i --force-architecture foundationdb-clients_6.3.23-1_amd64.deb rm -rf foundationdb-clients_6.3.23-1_amd64.deb - name: Install stable toolchain uses: dtolnay/rust-toolchain@stable with: toolchain: 1.71.1 targets: ${{ matrix.arch }} - name: Output package versions run: set -x; go version ; cargo version ; rustc --version ; cmake --version ; gcc --version ; g++ --version ; perl -v - name: Run cargo build run: cargo build ${{ matrix.opts }} --release --locked --target ${{ matrix.arch }} env: BINDGEN_EXTRA_CLANG_ARGS_aarch64-unknown-linux-gnu: "-I/usr/aarch64-linux-gnu/include/" - name: Package binaries if: ${{ !contains(matrix.arch, 'windows') }} shell: bash run: | cd target/${{ matrix.arch }}/release chmod +x surreal tar -zcvf ${{ matrix.file }}.tgz surreal echo $(shasum -a 256 ${{ matrix.file }}.tgz | cut -f1 -d' ') > ${{ matrix.file }}.txt - name: Package binaries if: ${{ contains(matrix.arch, 'windows') }} shell: bash run: | cd target/${{ matrix.arch }}/release cp surreal.exe ${{ matrix.file }}.exe echo $(shasum -a 256 ${{ matrix.file }}.exe | cut -f1 -d' ') > ${{ matrix.file }}.txt - name: Upload artifacts uses: actions/upload-artifact@v3 with: name: ${{ matrix.file }} path: | target/${{ matrix.arch }}/release/surreal target/${{ matrix.arch }}/release/${{ matrix.file }}.tgz target/${{ matrix.arch }}/release/${{ matrix.file }}.txt target/${{ matrix.arch }}/release/${{ matrix.file }}.exe crate: name: Publish surrealdb-nightly to crates.io needs: [lint, test] runs-on: ubuntu-latest steps: - name: Install stable toolchain uses: dtolnay/rust-toolchain@stable with: toolchain: stable - name: Checkout sources uses: actions/checkout@v4 - name: Publish env: CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }} shell: bash run: | # Replace the crate name # We are just going to replace the first occurance of surrealdb sed -i "0,/surrealdb/s//surrealdb-nightly/" lib/Cargo.toml # Get the date and time of the last commit date=$(git show --no-patch --format=%ad --date=format:%Y%m%d) time=$(git show --no-patch --format=%ad --date=format:%H%M%S) # Update the version to a nightly one # This sets the nightly version to something like `1.20231117.1130416` # The 1 at the beginning of the patch number is just so it never starts with zero sed -i "s#^version = \"\([[:digit:]]*\)\..*\"#version = \"\1.${date}.1${time}\"#" lib/Cargo.toml # Get the short commit shortRev=$(git rev-parse --short HEAD) # Update the description sed -i "s#^description = \".*\"#description = \"A nightly release of the surrealdb crate based on commit ${shortRev}\"#" lib/Cargo.toml # Commit changes # We are not going to push these changes. We do this because # some git commands `release-plz` runs do not work in detached state. git config --local user.email "actions@users.noreply.github.com" git config --local user.name "github-actions[bot]" git commit -am 'Prepare nightly release' git checkout -b nightly # Install release-plz cargo install --force --locked --version 0.3.30 release-plz # Publish cargo crate /home/runner/.cargo/bin/release-plz release --config .config/release-nightly-plz.toml docker: name: Build and publish Docker image needs: [build] runs-on: ubuntu-latest steps: - name: Checkout sources uses: actions/checkout@v3 - name: Download amd64 binary uses: actions/download-artifact@v3 with: name: surreal-nightly.linux-amd64 path: amd64 - name: Download arm64 binary uses: actions/download-artifact@v3 with: name: surreal-nightly.linux-arm64 path: arm64 - name: Set file permissions shell: bash run: | chmod +x amd64/surreal arm64/surreal - name: Configure DockerHub uses: docker/login-action@v2 with: username: ${{ secrets.DOCKER_USER }} password: ${{ secrets.DOCKER_PASS }} - name: Set up QEMU uses: docker/setup-qemu-action@v2 - name: Set up Buildx uses: docker/setup-buildx-action@v2 - name: Configure tag shell: bash run: | VERSION=nightly echo "VERSION=${VERSION}" >> $GITHUB_ENV - name: Build the Docker image uses: docker/build-push-action@v4 with: context: . load: true tags: surrealdb/surrealdb:${{ env.VERSION }} # Start the docker image as server and wait until it is ready - name: Test the Docker image run: | docker run --net=host --rm surrealdb/surrealdb:${{ env.VERSION }} start 2>&1 >surreal.log & retries=5 until docker run --net=host --rm surrealdb/surrealdb:${{ env.VERSION }} is-ready; do retries=$((retries-1)) if [[ $retries -eq 0 ]]; then echo "###" echo "### The container is not ready after 5 seconds!" echo "###" cat surreal.log echo "###" echo "### ERROR: The docker image is not valid. Aborting." echo "###" exit 1 fi sleep 1 done # This second build reuses the cache from the build above - name: Push the Docker image uses: docker/build-push-action@v4 with: context: . push: true platforms: linux/amd64,linux/arm64 tags: surrealdb/surrealdb:${{ env.VERSION }} publish: name: Publish binaries for ${{ matrix.arch }} needs: [docker] strategy: fail-fast: false matrix: include: - arch: x86_64-apple-darwin os: macos-latest file: surreal-nightly.darwin-amd64 - arch: aarch64-apple-darwin os: macos-latest file: surreal-nightly.darwin-arm64 - arch: x86_64-unknown-linux-gnu os: ubuntu-latest file: surreal-nightly.linux-amd64 - arch: aarch64-unknown-linux-gnu os: ubuntu-latest file: surreal-nightly.linux-arm64 - arch: x86_64-pc-windows-msvc os: windows-latest file: surreal-nightly.windows-amd64 runs-on: ${{ matrix.os }} steps: - name: Download artifacts uses: actions/download-artifact@v3 with: name: ${{ matrix.file }} - name: Configure AWS uses: aws-actions/configure-aws-credentials@v1-node16 with: aws-region: us-east-2 aws-access-key-id: ${{ secrets.AMAZON_ACCESS_KEY }} aws-secret-access-key: ${{ secrets.AMAZON_SECRET_KEY }} - name: Publish non-windows binaries if: ${{ !contains(matrix.arch, 'windows') }} shell: bash run: | aws s3 cp --cache-control 'no-store' ${{ matrix.file }}.tgz s3://download.surrealdb.com/nightly/ aws s3 cp --cache-control 'no-store' ${{ matrix.file }}.txt s3://download.surrealdb.com/nightly/ - name: Publish windows binaries if: ${{ contains(matrix.arch, 'windows') }} shell: bash run: | aws s3 cp --cache-control 'no-store' ${{ matrix.file }}.exe s3://download.surrealdb.com/nightly/ aws s3 cp --cache-control 'no-store' ${{ matrix.file }}.txt s3://download.surrealdb.com/nightly/ package-macos: name: Package macOS universal binary needs: [publish] runs-on: macos-latest steps: - name: Download amd64 binary uses: actions/download-artifact@v3 with: name: surreal-nightly.darwin-amd64 path: amd64 - name: Download arm64 binary uses: actions/download-artifact@v3 with: name: surreal-nightly.darwin-arm64 path: arm64 - name: Configure AWS uses: aws-actions/configure-aws-credentials@v1-node16 with: aws-region: us-east-2 aws-access-key-id: ${{ secrets.AMAZON_ACCESS_KEY }} aws-secret-access-key: ${{ secrets.AMAZON_SECRET_KEY }} - name: Package universal MacOS binary shell: bash run: | FILE="surreal-nightly.darwin-universal" lipo -create -output surreal amd64/surreal arm64/surreal chmod +x surreal tar -zcvf $FILE.tgz surreal echo $(shasum -a 256 $FILE.tgz | cut -f1 -d' ') > $FILE.txt aws s3 cp --cache-control 'no-store' $FILE.tgz s3://download.surrealdb.com/nightly/ aws s3 cp --cache-control 'no-store' $FILE.txt s3://download.surrealdb.com/nightly/ deploy: name: Deploy needs: [publish, package-macos] runs-on: ubuntu-latest steps: - name: Checkout sources uses: actions/checkout@v3 - name: Configure AWS uses: aws-actions/configure-aws-credentials@v1-node16 with: aws-region: us-east-2 aws-access-key-id: ${{ secrets.AMAZON_ACCESS_KEY }} aws-secret-access-key: ${{ secrets.AMAZON_SECRET_KEY }} - name: Distribute binaries shell: bash run: | regions=("af-south-1" "ap-east-1" "ap-south-1" "ap-southeast-1" "ap-southeast-2" "ca-central-1" "eu-central-1" "eu-west-2" "me-south-1" "sa-east-1" "us-west-2") for region in ${regions[@]}; do aws s3 sync --delete --storage-class INTELLIGENT_TIERING --source-region eu-west-2 --region ${region} s3://download.surrealdb.com s3://download.${region}.surrealdb.com done