Skip to content

Test Crystal & Shards #299

Test Crystal & Shards

Test Crystal & Shards #299

name: Test Crystal & Shards
on:
workflow_dispatch:
inputs:
crystal_repo:
default: 'crystal-lang/crystal'
required: true
crystal_branch:
default: 'master'
required: true
shards_repo:
default: 'crystal-lang/shards'
required: true
shards_branch:
default: 'master'
required: true
crystal_opts:
default: '--exclude-warnings none --error-on-warnings --error-trace'
required: false
shards_opts:
default: '--ignore-crystal-version'
required: false
crystal_build_opts:
default: 'release=1'
required: false
previous_crystal_release:
default: 'https://github.com/crystal-lang/crystal/releases/download/1.9.2/crystal-1.9.2-1-linux-x86_64.tar.gz'
required: true
jobs:
build:
runs-on: ubuntu-latest
container: ubuntu:latest
steps:
- name: Workflow Arguments
run: |
echo "crystal_repo: ${{ github.event.inputs.crystal_repo }}"
echo "crystal_branch: ${{ github.event.inputs.crystal_branch }}"
echo "shards_repo: ${{ github.event.inputs.shards_repo }}"
echo "shards_branch: ${{ github.event.inputs.shards_branch }}"
echo "crystal_opts: ${{ github.event.inputs.crystal_opts }}"
echo "shards_opts: ${{ github.event.inputs.shards_opts }}"
echo "crystal_build_opts: ${{ github.event.inputs.crystal_build_opts }}"
echo "previous_crystal_release: ${{ github.event.inputs.previous_crystal_release }}"
- name: Checkout test-ecosystem
uses: actions/checkout@v4
with:
path: test-ecosystem
- name: Install Libraries
run: |
apt-get update
./test-ecosystem/scripts/apt-install-tools.sh
./test-ecosystem/scripts/apt-install-llvm-libclang.sh
echo "LLVM_CONFIG=$LLVM_CONFIG" >> $GITHUB_ENV
./test-ecosystem/scripts/apt-install-crystal-deps.sh
# for https://github.com/actions/checkout/issues/209
apt-get install -y jq
- name: Install Previous Crystal
run: |
curl -fsSL ${{ github.event.inputs.previous_crystal_release }} -o /tmp/crystal.tar.gz
mkdir /tmp/crystal
tar -xz -C /tmp/crystal --strip-component=1 -f /tmp/crystal.tar.gz
echo "/tmp/crystal/bin/" >> $GITHUB_PATH
- name: Checkout Crystal
uses: actions/checkout@v4
with:
repository: ${{ github.event.inputs.crystal_repo }}
ref: ${{ github.event.inputs.crystal_branch }}
# https://github.com/actions/checkout#checkout-multiple-repos-private
token: ${{ secrets.MY_GITHUB_PAT }}
path: crystal
# https://github.com/actions/checkout/issues/209
- id: get-crystal-sha
run: |
echo ::set-output name=sha::$( curl -u "u:${{ secrets.MY_GITHUB_PAT }}" https://api.github.com/repos/${{ github.event.inputs.crystal_repo }}/git/ref/heads/${{ github.event.inputs.crystal_branch }} | jq .object.sha | tr -d '"' )
- name: Checkout Shards
uses: actions/checkout@v4
with:
repository: ${{ github.event.inputs.shards_repo }}
ref: ${{ github.event.inputs.shards_branch }}
# https://github.com/actions/checkout#checkout-multiple-repos-private
token: ${{ secrets.MY_GITHUB_PAT }}
path: shards
- id: get-shards-sha
run: |
echo ::set-output name=sha::$( curl -u "u:${{ secrets.MY_GITHUB_PAT }}" https://api.github.com/repos/${{ github.event.inputs.shards_repo }}/git/ref/heads/${{ github.event.inputs.shards_branch }} | jq .object.sha | tr -d '"' )
- name: Compute build cache keys
run: |
crystal env CRYSTAL_VERSION > ./build-cache-key
echo "LLVM_VERSION=$($LLVM_CONFIG --version)" >> ./build-cache-key
echo "crystal_build_opts=${{ github.event.inputs.crystal_build_opts }}" >> ./build-cache-key
cd crystal
echo "CRYSTAL_SHA1=${{ steps.get-crystal-sha.outputs.sha }}" >> ../build-cache-key
cd ../shards
echo "SHARDS_SHA1=${{ steps.get-shards-sha.outputs.sha }}" >> ../build-cache-key
cat ../build-cache-key
- name: Build cache
id: build-cache
uses: actions/cache@v3
with:
path: |
./crystal/.build/crystal
./shards/bin/shards
./crystal-lib
key: ${{ runner.os }}-build-${{ hashFiles('./build-cache-key') }}
- name: Build Crystal Deps
run: |
cd crystal
make deps
- name: Build Crystal
if: steps.build-cache.outputs.cache-hit != 'true'
run: |
mkdir crystal-lib
cp -r $(/tmp/crystal/bin/crystal env CRYSTAL_LIBRARY_PATH)/* ./crystal-lib/
cd crystal
make crystal CRYSTAL_CONFIG_LIBRARY_PATH=$(readlink -f ../crystal-lib) ${{ github.event.inputs.crystal_build_opts }}
bin/crystal --version
- name: Build Shards
if: steps.build-cache.outputs.cache-hit != 'true'
run: |
cd shards
make bin/shards CRYSTAL=../crystal/bin/crystal
bin/shards --version
- name: Artifact (with permissions)
uses: actions/cache@v3
with:
path: |
./test-ecosystem
./crystal
./shards
./crystal-lib
key: artifacts-${{ github.run_id }}-${{ github.run_number }}
# Workaround https://github.com/actions/download-artifact/issues/14
# - name: Upload artifacts
# uses: actions/upload-artifact@v2
# with:
# name: files
# path: |
# ./test-ecosystem
# ./crystal
# ./shards
# ./crystal-lib
test:
strategy:
matrix:
script:
- 00-crystal-init-spec.bats
- 01-shards.bats
- 10-crystal-db.bats
- 20-crystal-ext.bats
- 30-tools.bats
# - 40-web-frameworks-amber.bats
- 40-web-frameworks-kemal.bats
- 40-web-frameworks-lucky.bats
- 50-crystal.bats
- 60-crystal-progress.bats
- 70-implementations.bats
- 80-tutorials.bats
fail-fast: false
name: test ${{ matrix.script }}
runs-on: ubuntu-latest
container: ubuntu:latest
services:
postgres:
image: postgres:16.1-alpine
env:
POSTGRES_HOST_AUTH_METHOD: trust
mysql:
image: mysql:8.2
env:
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
redis:
image: redis:alpine
needs: build
steps:
- name: Artifact (with permissions)
uses: actions/cache@v3
with:
path: |
./test-ecosystem
./crystal
./shards
./crystal-lib
key: artifacts-${{ github.run_id }}-${{ github.run_number }}
# Workaround https://github.com/actions/download-artifact/issues/14
# - name: Download artifacts
# uses: actions/download-artifact@v2
# with:
# name: files
- name: Install Libraries
run: |
apt-get update
./test-ecosystem/scripts/apt-install-tools.sh
./test-ecosystem/scripts/apt-install-llvm-libclang.sh
echo "LLVM_CONFIG=$LLVM_CONFIG" >> $GITHUB_ENV
./test-ecosystem/scripts/apt-install-crystal-deps.sh
./test-ecosystem/scripts/00-install-bats.sh
- name: Initialize postgres
uses: docker://postgres:16.1-alpine
with:
args: /bin/sh -c "psql -U postgres -h postgres -f ./test-ecosystem/scripts/pg-init.sql"
- name: Initialize mysql
uses: docker://mysql:8.2
with:
args: /bin/sh -c "mysql -uroot -h mysql < ./test-ecosystem/scripts/mysql-init.sql"
- name: Configure git
run: |
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
- name: Setup env vars
run: |
echo "SHARDS_OPTS=${{ github.event.inputs.shards_opts }}" >> $GITHUB_ENV
echo "CRYSTAL_OPTS=${{ github.event.inputs.crystal_opts }}" >> $GITHUB_ENV
echo "CRYSTAL_LIBRARY_PATH=$(readlink -f ./crystal-lib)" >> $GITHUB_ENV
echo "REPOS_DIR=$(readlink -f ./repos)" >> $GITHUB_ENV
echo "SHARDS_OVERRIDE=$(readlink -f ./repos)/shard.override.yml" >> $GITHUB_ENV
echo "SHARDS_CACHE_PATH=$(readlink -f ./shards_cache)" >> $GITHUB_ENV
echo "$(readlink -f ./shards/bin)" >> $GITHUB_PATH
echo "$(readlink -f ./crystal/bin)" >> $GITHUB_PATH
echo "POSTGRES_HOST=postgres" >> $GITHUB_ENV
echo "MYSQL_HOST=mysql" >> $GITHUB_ENV
echo "REDIS_HOST=redis" >> $GITHUB_ENV
- name: Crystal & Shards information
run: |
which crystal
crystal --version
crystal env
which shards
shards --version
env | grep CRYSTAL
env | grep SHARDS
- run: ./test-ecosystem/scripts/10-clone-repos.sh
- run: bats ./test-ecosystem/bats/${{ matrix.script }}