From 083663e2652efaf83f37868c99daa38ecb68746c Mon Sep 17 00:00:00 2001 From: Niko Storni Date: Fri, 25 Aug 2023 02:12:05 +0200 Subject: [PATCH] add github actions --- .github/workflows/main.yml | 67 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..95e9815 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,67 @@ +name: CI + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-20.04 # equivalent to 'dist: focal' + + steps: + - name: Check out code + uses: actions/checkout@v2 + + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: '1.20' + + - name: Shutdown Default Ubuntu MySQL + run: sudo service mysql stop + + - name: Set up MySQL using mirromutth/mysql-action + uses: mirromutth/mysql-action@v1.1 + with: + mysql version: 'latest' + mysql database: 'commentron' + mysql root password: '' # Empty password + + - name: Before Install + run: | + sudo mysql -u root -e 'CREATE DATABASE IF NOT EXISTS commentron;' + sudo mysql -u root -e 'CREATE DATABASE IF NOT EXISTS social;' + sudo mysql -u root -e "CREATE USER 'lbry-rw'@'localhost' IDENTIFIED BY 'lbry';" + sudo mysql -u root -e "CREATE USER 'lbry-ro'@'localhost' IDENTIFIED BY 'lbry';" + sudo mysql -u root -e "GRANT ALL ON commentron.* TO 'lbry-rw'@'localhost';" + sudo mysql -u root -e "GRANT SELECT ON commentron.* TO 'lbry-ro'@'localhost';" + sudo mysql -u root -e "GRANT ALL ON social.* TO 'lbry-rw'@'localhost';" + + - name: Cache + uses: actions/cache@v2 + with: + path: | + ${{ runner.home }}/go/pkg/mod + ${{ runner.home }}/.cache/go-build + key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} + restore-keys: | + ${{ runner.os }}-go- + + - name: Run Scripts and Tests + run: | + ./scripts/build.sh + ./scripts/lint.sh + source ./scripts/setup.sh + ./bin/commentron serve & + sleep 5s + curl -i -H 'Accept: application/json' -H 'Content-Type: application/json' http://localhost:3306 + go test ./... + go mod tidy + git diff --exit-code + ./scripts/gen_models.sh + sqlboiler --version + git diff --exit-code + ./bin/commentron test + + - name: Deploy + if: github.event_name == 'push' + run: | + bash docker/docker.sh \ No newline at end of file