From 139017ba7c2d575fb27179b43e98ea177fa202cc Mon Sep 17 00:00:00 2001 From: saltycrys <73420320+saltycrys@users.noreply.github.com> Date: Tue, 1 Dec 2020 21:45:33 +0100 Subject: [PATCH 1/6] Switch to GitHub Actions for CI Travis CI is slow, builds are first queued up forever and then the builds themselves are slow, too. GitHub Actions run pretty much immediately and are fast. Also separate jobs run at the same time unlike on Travis CI. --- .github/workflows/ci.yml | 72 ++++++++++++++++++++++++++++++++++++++++ .travis.yml | 47 -------------------------- README.md | 2 +- 3 files changed, 73 insertions(+), 48 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 00000000..0d2cb8c3 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,72 @@ +name: Invidious CI + +on: [push, pull_request] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Install Crystal + uses: oprypin/install-crystal@v1.2.4 + + # - name: Cache dependencies + # uses: actions/cache@v2 + # with: + # path: ./lib + # key: shards-${{ hashFiles('shard.lock') }} # shard.lock isn't tracked atm + + # Docs at https://crystal-lang.org/reference/the_shards_command + # + # `shards install` + # + # Resolves and installs dependencies into the lib folder. If not already present, generates a shard.lock + # file from resolved dependencies, locking version numbers or Git commits. + # Reads and enforces locked versions and commits if a shard.lock file is present. The install command may + # fail if a locked version doesn't match a requirement, but may succeed if a new dependency was added, as + # long as it doesn't generate a conflict, thus generating a new shard.lock file. + # + # `shards update` + # + # Resolves and updates all dependencies into the lib folder again, whatever the locked versions and + # commits in the shard.lock file. Eventually generates a new shard.lock file. + # + # -------------------------------------------------------------------------------- + # + # running either `shards install` or `shards update` without a `shard.lock` file does the same thing, + # downloading shards into the `lib` folder and writing a `shard.lock` file + # + # if there is a `shard.lock` file `shards install` installs the versions from the lock file while + # `shards update` does a `shards install` that pretends there isn't a lock file present + - name: Update and install shards + run: shards update + + - name: Run tests + run: crystal spec + + - name: Run lint + run: | + if ! crystal tool format --check; then + crystal tool format + exit 1 + fi + + - name: Build + run: crystal build --warnings all --error-on-warnings --error-trace src/invidious.cr + + build-docker: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Build Docker + run: docker-compose up -d + + - name: Test Docker + run: while curl -Isf http://localhost:3000; do sleep 1; done + diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f443e815..00000000 --- a/.travis.yml +++ /dev/null @@ -1,47 +0,0 @@ -dist: bionic - -# Work around broken Travis Crystal image -addons: - apt: - packages: - - gcc - - pkg-config - - git - - tzdata - - libpcre3-dev - - libevent-dev - - libyaml-dev - - libgmp-dev - - libssl-dev - - libxml2-dev - -jobs: - include: - - stage: build - # TODO: Shallowly clone again once the .git folder is no longer required for building - git: - depth: false - language: crystal - crystal: latest - before_install: - - crystal --version - - shards update - - shards install - install: - - crystal build --warnings all --error-on-warnings src/invidious.cr - script: - - crystal tool format --check - - crystal spec - - - stage: build_docker - # TODO: Shallowly clone again once the .git folder is no longer required for building - git: - depth: false - language: minimal - services: - - docker - install: - - docker-compose build - script: - - docker-compose up -d - - while curl -Isf http://localhost:3000; do sleep 1; done diff --git a/README.md b/README.md index 64017379..91e36daf 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Invidious -[![Build Status](https://travis-ci.org/iv-org/invidious.svg?branch=master)](https://travis-ci.org/github/iv-org/invidious) [![Translation Status](https://hosted.weblate.org/widgets/invidious/-/translations/svg-badge.svg)](https://hosted.weblate.org/engage/invidious/) +[![Build Status](https://github.com/iv-org/invidious/workflows/Invidious%20CI/badge.svg)](https://github.com/iv-org/invidious/actions) [![Translation Status](https://hosted.weblate.org/widgets/invidious/-/translations/svg-badge.svg)](https://hosted.weblate.org/engage/invidious/) ## Invidious is an alternative front-end to YouTube From 0fa1567793f688dfef4ce5447f117ff560dd7451 Mon Sep 17 00:00:00 2001 From: saltycrys <73420320+saltycrys@users.noreply.github.com> Date: Wed, 2 Dec 2020 01:32:19 +0100 Subject: [PATCH 2/6] Display lint fixes on lint error --- .github/workflows/ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0d2cb8c3..d18998b1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,6 +51,7 @@ jobs: run: | if ! crystal tool format --check; then crystal tool format + git diff exit 1 fi From 4fb360b19f6c185eafd0ebd47a858fb501ec1776 Mon Sep 17 00:00:00 2001 From: saltycrys <73420320+saltycrys@users.noreply.github.com> Date: Wed, 2 Dec 2020 04:39:55 +0100 Subject: [PATCH 3/6] Track shard.lock --- .gitignore | 1 - shard.lock | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 shard.lock diff --git a/.gitignore b/.gitignore index c1ca4c20..3bbfccf0 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,3 @@ /.vscode/ /invidious /sentry -shard.lock diff --git a/shard.lock b/shard.lock new file mode 100644 index 00000000..1cf34ae7 --- /dev/null +++ b/shard.lock @@ -0,0 +1,42 @@ +version: 2.0 +shards: + db: + git: https://github.com/crystal-lang/crystal-db.git + version: 0.9.0 + + exception_page: + git: https://github.com/crystal-loot/exception_page.git + version: 0.1.4 + + kemal: + git: https://github.com/kemalcr/kemal.git + version: 0.26.1+git.commit.dfe7dca08f4c9a9456d6132af5f6b59fcd6865e4 + + kilt: + git: https://github.com/jeromegn/kilt.git + version: 0.4.0 + + lsquic: + git: https://github.com/iv-org/lsquic.cr.git + version: 2.18.1-1 + + pg: + git: https://github.com/will/crystal-pg.git + version: 0.21.1 + + pool: + git: https://github.com/ysbaddaden/pool.git + version: 0.2.3 + + protodec: + git: https://github.com/omarroth/protodec.git + version: 0.1.3 + + radix: + git: https://github.com/luislavena/radix.git + version: 0.3.9 + + sqlite3: + git: https://github.com/crystal-lang/crystal-sqlite3.git + version: 0.16.0 + From 2b6b0e62f4526063c71c225ffeea5ebdb98c74c6 Mon Sep 17 00:00:00 2001 From: saltycrys <73420320+saltycrys@users.noreply.github.com> Date: Wed, 2 Dec 2020 04:40:13 +0100 Subject: [PATCH 4/6] Add shard caching to CI --- .github/workflows/ci.yml | 67 +++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d18998b1..1f553807 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,39 +10,48 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Install Crystal - uses: oprypin/install-crystal@v1.2.4 - - # - name: Cache dependencies + # - name: Find out latest Crystal version + # run: | + # crystal_latest=$(curl -ILs -o /dev/null -w %{url_effective} https://github.com/crystal-lang/crystal/releases/latest | grep -o '[^/]*$') + # echo "crystal_latest=$crystal_latest" >> $GITHUB_ENV + # echo $crystal_latest + # + # - name: Cache Crystal # uses: actions/cache@v2 # with: - # path: ./lib - # key: shards-${{ hashFiles('shard.lock') }} # shard.lock isn't tracked atm - - # Docs at https://crystal-lang.org/reference/the_shards_command - # - # `shards install` - # - # Resolves and installs dependencies into the lib folder. If not already present, generates a shard.lock - # file from resolved dependencies, locking version numbers or Git commits. - # Reads and enforces locked versions and commits if a shard.lock file is present. The install command may - # fail if a locked version doesn't match a requirement, but may succeed if a new dependency was added, as - # long as it doesn't generate a conflict, thus generating a new shard.lock file. - # - # `shards update` - # - # Resolves and updates all dependencies into the lib folder again, whatever the locked versions and - # commits in the shard.lock file. Eventually generates a new shard.lock file. + # path: ./crystal-bin + # key: crystal-${{ env.crystal_latest }} # - # -------------------------------------------------------------------------------- + # - name: Add custom Crystal dir to path + # run: echo "./crystal-bin" >> $GITHUB_PATH # - # running either `shards install` or `shards update` without a `shard.lock` file does the same thing, - # downloading shards into the `lib` folder and writing a `shard.lock` file - # - # if there is a `shard.lock` file `shards install` installs the versions from the lock file while - # `shards update` does a `shards install` that pretends there isn't a lock file present - - name: Update and install shards - run: shards update + # - name: Find out installed Crystal version + # run: | + # if ! [ -x "$(command -v crystal)" ]; then + # crystal_installed="none" + # else + # crystal_installed=$(crystal version | grep Crystal | awk '{print $2}') + # fi + # echo "crystal_installed=$crystal_installed" >> $GITHUB_ENV + # echo $crystal_installed + + - name: Install Crystal + uses: oprypin/install-crystal@v1.2.4 + # if: env.crystal_installed != env.crystal_latest + # with: + # destination: ./crystal-bin + + - name: Cache Shards + uses: actions/cache@v2 + with: + path: ./lib + key: shards-${{ hashFiles('shard.lock') }} + + - name: Install Shards + run: | + if ! shards check; then + shards install + fi - name: Run tests run: crystal spec From 21c1450e4adea2a27304cf921f7445d4dc5ca5c8 Mon Sep 17 00:00:00 2001 From: saltycrys <73420320+saltycrys@users.noreply.github.com> Date: Wed, 2 Dec 2020 05:33:42 +0100 Subject: [PATCH 5/6] Run CI only once per change --- .github/workflows/ci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1f553807..b354538c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,6 +1,10 @@ name: Invidious CI -on: [push, pull_request] +on: + push: + branches: "master" + pull_request: + branches: "*" jobs: build: From eb6d3d68a9ed880fe0e3e4b6404925d0f4a4c5ad Mon Sep 17 00:00:00 2001 From: saltycrys <73420320+saltycrys@users.noreply.github.com> Date: Thu, 3 Dec 2020 13:06:27 +0100 Subject: [PATCH 6/6] Run CI on `api-only` branch, too --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b354538c..affa7337 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,9 @@ name: Invidious CI on: push: - branches: "master" + branches: + - "master" + - "api-only" pull_request: branches: "*"