149 lines
4.3 KiB
YAML
149 lines
4.3 KiB
YAML
name: CI
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
pull_request:
|
|
|
|
env:
|
|
RAILS_ENV: test
|
|
PGUSER: discourse
|
|
PGPASSWORD: discourse
|
|
LOAD_PLUGINS: 1
|
|
|
|
jobs:
|
|
lint:
|
|
runs-on: ubuntu-latest
|
|
container: discourse/discourse_test:slim
|
|
timeout-minutes: 20
|
|
|
|
steps:
|
|
- name: Set working directory owner
|
|
run: chown -R root:root .
|
|
|
|
- uses: actions/checkout@v4
|
|
|
|
- name: Install JS dependencies
|
|
run: pnpm install --frozen-lockfile
|
|
|
|
- name: Bundle install
|
|
run: bundle install
|
|
|
|
- name: Rubocop
|
|
run: bundle exec rubocop .
|
|
|
|
- name: Syntax Tree
|
|
run: bundle exec stree check Gemfile $(git ls-files '*.rb')
|
|
|
|
- name: ESLint, Stylelint, Prettier and Types
|
|
run: pnpm lint
|
|
|
|
tests:
|
|
runs-on: ubuntu-latest
|
|
container: discourse/discourse_test:slim-browsers
|
|
timeout-minutes: 60
|
|
|
|
steps:
|
|
- name: Set working directory owner
|
|
run: chown -R root:root .
|
|
|
|
- name: Checkout plugin
|
|
uses: actions/checkout@v4
|
|
with:
|
|
path: plugin
|
|
|
|
- name: Clone Discourse core
|
|
run: git clone --depth 1 --branch latest https://github.com/discourse/discourse.git core
|
|
|
|
- name: Install plugin
|
|
run: cp -r plugin core/plugins/hledger
|
|
|
|
- name: Container envs
|
|
id: container-envs
|
|
run: |
|
|
echo "ruby_version=$RUBY_VERSION" >> "$GITHUB_OUTPUT"
|
|
echo "debian_release=$DEBIAN_RELEASE" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Bundler cache
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: core/vendor/bundle
|
|
key: ${{ runner.os }}-${{ steps.container-envs.outputs.ruby_version }}-${{ steps.container-envs.outputs.debian_release }}-gems-${{ hashFiles('core/Gemfile.lock') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-${{ steps.container-envs.outputs.ruby_version }}-${{ steps.container-envs.outputs.debian_release }}-gems-
|
|
|
|
- name: Get pnpm store directory
|
|
id: pnpm-store
|
|
working-directory: core
|
|
run: echo "dir=$(pnpm store path)" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: pnpm cache
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ${{ steps.pnpm-store.outputs.dir }}
|
|
key: ${{ runner.os }}-pnpm-${{ hashFiles('core/pnpm-lock.yaml') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-pnpm-
|
|
|
|
- name: App state cache
|
|
id: app-cache
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: core/tmp/app-cache
|
|
key: ${{ runner.os }}-app-v1-${{ hashFiles('core/db/**/*', 'core/plugins/hledger/db/**/*', 'plugin/.gitea/workflows/ci.yml') }}
|
|
|
|
- name: Install hledger
|
|
run: |
|
|
apt-get update
|
|
apt-get install -y --no-install-recommends hledger
|
|
hledger --version
|
|
|
|
- name: Start Redis
|
|
run: redis-server /etc/redis/redis.conf &
|
|
|
|
- name: Start Postgres
|
|
working-directory: core
|
|
run: |
|
|
chown -R postgres /var/run/postgresql
|
|
sudo -E -u postgres script/start_test_db.rb
|
|
sudo -u postgres psql -c "CREATE ROLE $PGUSER LOGIN SUPERUSER PASSWORD '$PGPASSWORD';"
|
|
|
|
- name: Setup gems
|
|
working-directory: core
|
|
run: |
|
|
bundle config set --local path vendor/bundle
|
|
bundle config set --local without development
|
|
bundle config set --local deployment true
|
|
bundle install
|
|
|
|
- name: Install JS dependencies
|
|
working-directory: core
|
|
run: pnpm install --frozen-lockfile
|
|
|
|
- name: Restore database from cache
|
|
if: steps.app-cache.outputs.cache-hit == 'true'
|
|
working-directory: core
|
|
run: |
|
|
psql -f tmp/app-cache/cache.sql postgres
|
|
rm -rf public/uploads && cp -r tmp/app-cache/uploads public/uploads
|
|
|
|
- name: Create and migrate database
|
|
if: steps.app-cache.outputs.cache-hit != 'true'
|
|
working-directory: core
|
|
run: |
|
|
bin/rake db:create
|
|
bin/rake db:migrate
|
|
mkdir -p tmp/app-cache
|
|
pg_dumpall > tmp/app-cache/cache.sql
|
|
rm -rf tmp/app-cache/uploads && cp -r public/uploads tmp/app-cache/uploads
|
|
|
|
- name: Plugin RSpec
|
|
working-directory: core
|
|
run: bin/rspec plugins/hledger/spec/lib plugins/hledger/spec/requests
|
|
|
|
- name: Plugin QUnit
|
|
working-directory: core
|
|
env:
|
|
DISCOURSE_DISABLE_BROWSER_SANDBOX: "1"
|
|
run: bin/rake plugin:qunit['hledger'] |