name: Continuous Integration
env:
BUILD_OUTPUT: "./target/release/redgold"
AWS_EC2_METADATA_DISABLED: true
S3_RELEASE_PREFIX: "s3://redgold-public/release"
S3_EXPLORER_PREFIX: "s3://redgold-explorer"
S3_DOCS_PREFIX: "s3://redgold-docs"
DOCKER_USER: "redgoldio"
TOOLCHAIN: "stable"
DATABASE_URL: "sqlite:///home/runner/work/redgold-core/redgold-core/.rg/sqlx/data_store.sqlite"
on: push
jobs:
test:
if:
${{ !contains('
refs/heads/predev
refs/heads/dev
refs/heads/staging
refs/heads/test
refs/heads/main
', github.ref) }}
runs-on: ubuntu-latest-m
timeout-minutes: 60
permissions:
contents: write
outputs:
version: ${{ steps.version.outputs.version }}
# env:
# DATABASE_URL: "sqlite:///home/runner/work/redgold-core/redgold-core/.rg/sqlx/data_store.sqlite"
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14'
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ env.TOOLCHAIN }}
- uses: Swatinem/rust-cache@v1
with:
cache-on-failure: true
- run: echo "BRANCH=${GITHUB_REF##*/}" >> $GITHUB_ENV
- run: echo "Github branch = ${{ env.BRANCH }}"
- run: export VERSION=$(head Cargo.toml | grep 'version = ' | cut -d "=" -f 2 | tr -d ' "'); echo "VERSION=$VERSION" >> $GITHUB_ENV
- id: version
run: echo "version=${{env.VERSION}}" >> "$GITHUB_OUTPUT"
- run: echo "Testing version = ${{ env.VERSION }}"
- run: ./bin/install_build_deps.sh
- run: cargo clean
- run: export RUST_MIN_STACK=20485760; cargo test --lib -- --test-threads=1
- run: ./bin/local_test.sh
build-vue:
runs-on: self-hosted
if: contains('
refs/heads/dev
refs/heads/staging
refs/heads/test
refs/heads/main
', github.ref)
timeout-minutes: 60
steps:
- uses: actions/checkout@v2
- run: echo "BRANCH=${GITHUB_REF##*/}" >> $GITHUB_ENV
- run: echo "Github branch = ${{ env.BRANCH }}"
- name: Build Explorer
run: |
cd vue-explorer;
npm install
npm run build;
- name: Build Docs
run: |
cd docs;
npm install
npm run generate
- name: Configure AWS Keys
run: |
aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS }}
aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET }}
- name: Upload Explorer Distribution to S3
run: aws s3 rm --recursive ${{env.S3_EXPLORER_PREFIX}}-${{env.BRANCH}} && aws s3 cp --recursive ./vue-explorer/dist/ ${{env.S3_EXPLORER_PREFIX}}-${{env.BRANCH}}/
- name: Upload Docs Distribution to S3
run: aws s3 rm --recursive ${{env.S3_DOCS_PREFIX}}-${{env.BRANCH}} && aws s3 cp --recursive ./docs/dist/ ${{env.S3_DOCS_PREFIX}}-${{env.BRANCH}}/
build-linux:
# needs: [test]
if:
contains('
refs/heads/predev
refs/heads/dev
refs/heads/staging
refs/heads/test
refs/heads/main
', github.ref)
runs-on: ubuntu-latest-m
timeout-minutes: 100
permissions:
contents: write
# env:
# DATABASE_URL: "sqlite:///home/runner/work/redgold-core/redgold-core/.rg/sqlx/data_store.sqlite"
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '14'
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ env.TOOLCHAIN }}
- uses: Swatinem/rust-cache@v1
with:
cache-on-failure: true
- run: echo "BRANCH=${GITHUB_REF##*/}" >> $GITHUB_ENV
- run: echo "Github branch = ${{ env.BRANCH }}"
- run: export VERSION=$(head Cargo.toml | grep 'version = ' | cut -d "=" -f 2 | tr -d ' "'); echo "VERSION=$VERSION" >> $GITHUB_ENV
- run: echo "Testing version = ${{ env.VERSION }}"
- run: ./bin/install_build_deps.sh
- run: rustup toolchain list
- run: rustup default nightly
- run: rustup update
- run: rustup -V
- run: cargo clean
- run: export RUST_MIN_STACK=20485760; cargo test --lib -- --test-threads=1
- run: cargo build --release
- run: cp ${{ env.BUILD_OUTPUT }} ./redgold_linux
- uses: actions/upload-artifact@v3
with:
name: redgold_linux
path: ./redgold_linux
build-linux-ubuntu-20:
if:
contains('
refs/heads/predev
refs/heads/dev
refs/heads/staging
refs/heads/test
refs/heads/main
', github.ref)
runs-on: ubuntu-20.04
timeout-minutes: 100
permissions:
contents: write
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ env.TOOLCHAIN }}
- uses: Swatinem/rust-cache@v1
with:
cache-on-failure: true
- run: ./bin/install_build_deps.sh
- run: cargo build --release
- run: cp ${{ env.BUILD_OUTPUT }} ./redgold_linux_ubuntu20
- uses: actions/upload-artifact@v3
with:
name: redgold_linux_ubuntu20
path: ./redgold_linux_ubuntu20
build-windows:
# needs: [test]
if:
contains('
refs/heads/predev
refs/heads/dev
refs/heads/staging
refs/heads/test
refs/heads/main
', github.ref)
runs-on: windows-latest
timeout-minutes: 100
permissions:
contents: write
env:
DATABASE_URL: "sqlite:///Users/runner/work/redgold-core/redgold-core/.rg/sqlx/data_store.sqlite"
outputs:
release_match: ${{ steps.check-branch.outputs.match }}
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Install latest rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.TOOLCHAIN }}
target: x86_64-pc-windows-gnu
default: true
override: true
- uses: msys2/setup-msys2@v2
- run: echo "asdf" > ./redgold.exe
# Currently broken due to external change.
# - shell: msys2 {0}
# name: "Msys2 cargo build with dependencies"
# if:
# contains('
- uses: actions/upload-artifact@v3
with:
name: redgold.exe
path: ./redgold.exe
build-mac:
if:
contains('
refs/heads/predev
refs/heads/dev
refs/heads/staging
refs/heads/test
refs/heads/main
', github.ref)
runs-on: macos-latest
timeout-minutes: 100
permissions:
contents: write
env:
DATABASE_URL: "sqlite:///Users/runner/work/redgold-core/redgold-core/.rg/sqlx/data_store.sqlite"
outputs:
release_match: ${{ steps.check-branch.outputs.match }}
steps:
- name: Checkout
uses: actions/checkout@v1
# - name: Cache Rust dependencies
# uses: actions/cache@v1.0.1
# with:
# path: target
# key: ${{ runner.OS }}-build-${{ hashFiles('**/Cargo.lock') }}
- name: Install latest rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.TOOLCHAIN }}
target: x86_64-apple-darwin
default: true
override: true
- name: Check branch
id: check-branch
run: ./bin/release_branches.sh
- run: echo "release branch match output ${{ steps.check-branch.outputs.match }}"
- run: echo steps.check-branch.outputs.match
- run: echo "asdf" > ./redgold_mac
- if:
contains('
refs/heads/staging
refs/heads/test
refs/heads/main
', github.ref)
run: cargo clean; cargo build --release; cp ${{ env.BUILD_OUTPUT }} ./redgold_mac
- uses: actions/upload-artifact@v3
with:
name: redgold_mac
path: ./redgold_mac
release:
needs: [build-linux, build-mac, build-linux-ubuntu-20, build-windows, build-vue]
if:
contains('
refs/heads/predev
refs/heads/dev
refs/heads/staging
refs/heads/test
refs/heads/main
', github.ref)
runs-on: ubuntu-latest-m
timeout-minutes: 100
permissions:
contents: write
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- uses: actions/download-artifact@v3
with:
name: redgold_linux
- uses: actions/download-artifact@v3
with:
name: redgold_linux_ubuntu20
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ env.TOOLCHAIN }}
- uses: Swatinem/rust-cache@v1
with:
cache-on-failure: true
# - uses: actions/download-artifact@v3
# with:
# name: redgold_mac
- run: sleep 10
- name: Download redgold_mac artifact
# if: contains('
uses: actions/download-artifact@v3
with:
name: redgold_mac
- name: Download redgold.exe windows artifact
uses: actions/download-artifact@v3
with:
name: redgold.exe
- name: Check branch
id: check-branch
run: ./bin/release_branches.sh
shell: bash
- name: Cargo Publish
if:
contains('
refs/heads/staging
', github.ref)
run: |
echo "Branch is release branch, doing cargo publish"
cargo login ${{ secrets.CARGO_TOKEN }} &&
./bin/install_build_deps.sh &&
./bin/cargo_publish.sh
- run: ls -lA .
- run: ls -lA ./redgold_linux
- run: echo "BRANCH=${GITHUB_REF##*/}" >> $GITHUB_ENV
- run: echo "Github branch = ${{ env.BRANCH }}"
- run: export VERSION=$(head Cargo.toml | grep 'version = ' | cut -d "=" -f 2 | tr -d ' "'); echo "VERSION=$VERSION" >> $GITHUB_ENV
- run: echo "Testing version = ${{ env.VERSION }}"
- run: echo "BUILD_CHECKSUM=$(md5sum ./redgold_linux | cut -d ' ' -f 1 | tr -d ' ')" >> $GITHUB_ENV
- run: echo "BUILD_CHECKSUM_SHA256=$(shasum -a 256 ./redgold_linux | cut -d ' ' -f 1 | tr -d ' ')" >> $GITHUB_ENV
- run: echo "BUILD_SHORT_CHECKSUM=$(echo ${{env.BUILD_CHECKSUM_SHA256}} | tail -c 9)" >> $GITHUB_ENV
- run: echo "BUILD_CHECKSUM_SHA512=$(shasum -a 512 ./redgold_linux | cut -d ' ' -f 1 | tr -d ' ')" >> $GITHUB_ENV
- run: echo "WINDOWS_CHECKSUM=$(shasum -a 256 ./redgold.exe | cut -d ' ' -f 1 | tr -d ' ')" >> $GITHUB_ENV
- name: Calculate Mac SHA256 Checksum
if:
contains('
refs/heads/staging
refs/heads/test
refs/heads/main
', github.ref)
run: echo "MAC_BUILD_CHECKSUM_SHA256=$(shasum -a 256 ./redgold_mac | cut -d ' ' -f 1 | tr -d ' ')" >> $GITHUB_ENV
- if:
contains('
refs/heads/predev
refs/heads/dev
', github.ref)
run: echo "MAC_BUILD_CHECKSUM_SHA256=" >> $GITHUB_ENV
- run: chmod +x ./redgold_linux && chmod +x ./redgold_mac && chmod +X ./redgold.exe && chmod +x ./redgold_linux_ubuntu20
# Docker Image
# TODO: This works but need to setup self hosted registry also
- run: rm -rf docker-build-tmp || true
- run: mkdir docker-build-tmp
- run: cp ./redgold_linux docker-build-tmp/redgold; chmod +x docker-build-tmp/redgold
- run: cp release.Dockerfile docker-build-tmp/release.Dockerfile
- run: docker rmi --force ${{ env.DOCKER_USER }}/redgold:${{env.VERSION}} || true
- run: docker rmi --force ${{ env.DOCKER_USER }}/redgold:${{ env.BRANCH }} || true
- run: cd docker-build-tmp; docker build -f release.Dockerfile -t ${{ env.DOCKER_USER }}/redgold:${{env.VERSION}} .; cd ..
- run: echo ${{ secrets.DOCKER_TOKEN }} | docker login --username ${{ env.DOCKER_USER }} --password-stdin
- run: docker tag ${{ env.DOCKER_USER }}/redgold:${{env.VERSION}} ${{ env.DOCKER_USER }}/redgold:${{ env.BRANCH }}
- run: docker image push ${{ env.DOCKER_USER }}/redgold:${{ env.BRANCH }}
- name: Push Docker Versioned Image
if: steps.check-branch.outputs.match == '1'
run: docker image push ${{ env.DOCKER_USER }}/redgold:${{env.VERSION}}
- run: export DOCKER_SHA256=$(docker inspect --format='{{index .RepoDigests 0}}' ${{ env.DOCKER_USER }}/redgold:${{env.BRANCH}} | cut -d ':' -f 2 | tr -d ' '); echo "DOCKER_SHA256=$DOCKER_SHA256" >> $GITHUB_ENV
- run: curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
- run: unzip awscliv2.zip
- run: sudo ./aws/install --update
- run: aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS }}
- run: aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET }}
- run: echo ${{ env.DOCKER_SHA256 }} > docker_sha256_checksum
- run: aws s3 cp docker_sha256_checksum ${{ env.S3_RELEASE_PREFIX }}/${{ env.BRANCH }}/docker_sha256_checksum
- if: steps.check-branch.outputs.match == '1'
run: aws s3 cp docker_sha256_checksum ${{ env.S3_RELEASE_PREFIX }}/v/${{env.VERSION}}/docker_sha256_checksum
- run: echo ${{ env.BUILD_CHECKSUM }} > md5_checksum
- run: echo ${{ env.BUILD_CHECKSUM_SHA256 }} > sha256_checksum
- run: echo ${{ env.BUILD_CHECKSUM_SHA512 }} > sha512_checksum
- run: aws s3 cp redgold_linux ${{ env.S3_RELEASE_PREFIX }}/${{ env.BRANCH }}/redgold_linux
- run: aws s3 cp md5_checksum ${{ env.S3_RELEASE_PREFIX }}/${{ env.BRANCH }}/redgold_linux_md5_checksum
- run: aws s3 cp sha256_checksum ${{ env.S3_RELEASE_PREFIX }}/${{ env.BRANCH }}/redgold_linux_sha256_checksum
- run: aws s3 cp sha512_checksum ${{ env.S3_RELEASE_PREFIX }}/${{ env.BRANCH }}/redgold_linux_sha512_checksum
- run: echo ${{ env.MAC_BUILD_CHECKSUM_SHA256 }} > mac_sha256_checksum
- run: aws s3 cp mac_sha256_checksum ${{ env.S3_RELEASE_PREFIX }}/${{ env.BRANCH }}/redgold_mac_sha256_checksum
- run: aws s3 cp redgold_mac ${{ env.S3_RELEASE_PREFIX }}/${{ env.BRANCH }}/redgold_mac
- run: echo ${{ env.WINDOWS_CHECKSUM }} > windows_checksum
- run: aws s3 cp windows_checksum ${{ env.S3_RELEASE_PREFIX }}/${{ env.BRANCH }}/redgold_windows_checksum
- run: aws s3 cp redgold.exe ${{ env.S3_RELEASE_PREFIX }}/${{ env.BRANCH }}/redgold.exe
- if:
contains('
refs/heads/staging
', github.ref)
run: |
aws s3 cp redgold_linux ${{ env.S3_RELEASE_PREFIX }}/v/${{env.VERSION}}/redgold_linux &&
aws s3 cp md5_checksum ${{ env.S3_RELEASE_PREFIX }}/v/${{env.VERSION}}/redgold_linux_md5_checksum &&
aws s3 cp sha256_checksum ${{ env.S3_RELEASE_PREFIX }}/v/${{env.VERSION}}/redgold_linux_sha256_checksum &&
aws s3 cp sha512_checksum ${{ env.S3_RELEASE_PREFIX }}/v/${{env.VERSION}}/redgold_linux_sha512_checksum &&
aws s3 cp docker_sha256_checksum ${{ env.S3_RELEASE_PREFIX }}/v/${{env.VERSION}}/docker_sha256_checksum &&
aws s3 cp mac_sha256_checksum ${{ env.S3_RELEASE_PREFIX }}/v/${{env.VERSION}}/redgold_mac_sha256_checksum &&
aws s3 cp windows_checksum ${{ env.S3_RELEASE_PREFIX }}/v/${{env.VERSION}}/windows_checksum &&
aws s3 cp redgold_mac ${{ env.S3_RELEASE_PREFIX }}/v/${{env.VERSION}}/redgold_mac
aws s3 cp redgold.exe ${{ env.S3_RELEASE_PREFIX }}/v/${{env.VERSION}}/redgold.exe
# - run: cd .; echo 'Intended upload path: s3://${{env.S3_EXPLORER_PREFIX}}-${{env.BRANCH}}'
- uses: dev-drprasad/delete-tag-and-release@v0.2.1
with:
delete_release: true tag_name: release/${{ env.BRANCH }} env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Sleep for 5 seconds
run: sleep 5
- name: Release Env
uses: softprops/action-gh-release@v1
with:
files: |
redgold_linux
redgold_mac
redgold.exe
redgold_linux_ubuntu20
tag_name: "release/${{ env.BRANCH }}"
name: ${{ env.BRANCH }}
body: "
Redgold Release
env=${{ env.BRANCH }}
version=${{ env.VERSION }}
commit=${{ github.sha }}
docker=${{ env.DOCKER_SHA256 }}
linux_sha256=${{ env.BUILD_CHECKSUM_SHA256 }}
linux_sha256_end=${{ env.BUILD_SHORT_CHECKSUM }}
mac_sha256=${{ env.MAC_BUILD_CHECKSUM_SHA256 }}
windows_sha256=${{ env.WINDOWS_CHECKSUM }}
build_number=${{ github.run_number }}
"
token: ${{ secrets.GITHUB_TOKEN }}
- if:
contains('
refs/heads/staging
', github.ref)
uses: dev-drprasad/delete-tag-and-release@v0.2.1
with:
delete_release: true # default: false
tag_name: release/${{ env.VERSION }} # tag name to delete
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Sleep for 5 seconds
run: sleep 5
# https://github.com/marketplace/actions/rust-release-binary these steps came from below
# TODO: Duplicate this release step with 'version' tagged releases
- if:
contains('
refs/heads/staging
', github.ref)
name: Release Versioned
uses: softprops/action-gh-release@v1
with:
files: |
redgold_linux
redgold_mac
redgold.exe
tag_name: "release/${{ env.VERSION }}"
name: ${{ env.VERSION }}
# ${{steps.build_changelog.outputs.changelog}}
body: "
Redgold Release
version=${{ env.VERSION }}
commit=${{ github.sha }}
docker=${{ env.DOCKER_SHA256 }}
linux_sha256=${{ env.BUILD_CHECKSUM_SHA256 }}
linux_sha256_end=${{ env.BUILD_SHORT_CHECKSUM }}
mac_sha256=${{ env.MAC_BUILD_CHECKSUM_SHA256 }}
windows_sha256=${{ env.WINDOWS_CHECKSUM }}
build_number=${{ github.run_number }}
"
token: ${{ secrets.GITHUB_TOKEN }}