diff --git a/.github/actions/action.yml b/.github/actions/action.yml new file mode 100644 index 00000000..1e407006 --- /dev/null +++ b/.github/actions/action.yml @@ -0,0 +1,5 @@ +name: 'Build local dockerfile' +description: 'Builds local dockerfile and runs the defailt action' +runs: + using: 'docker' + image: '../images/Dockerfile' diff --git a/.github/images/Dockerfile b/.github/images/Dockerfile new file mode 100644 index 00000000..b2fd2470 --- /dev/null +++ b/.github/images/Dockerfile @@ -0,0 +1,49 @@ +FROM quay.io/centos/centos:stream8 AS base + +ENV PGHOST=postgres +ENV PGUSER=foreman +ENV PGPASS=foreman +ENV RAILS_ENV=test +ENV GIT_COMMITTER_NAME="gh_actions" +ENV GIT_COMMITTER_EMAIL="gh_actions@foreman_virt_who_configure.foreman" +ENV WORKDIR=/projects/foreman +ENV BUNDLE_PATH=vendor/bundle + +RUN \ + dnf module install -y ruby:2.7 postgresql:12;\ + dnf install -y epel-release; \ + dnf install -y redhat-rpm-config libpq-devel ruby-devel systemd-devel make tar libvirt-devel zlib-devel libxml2-devel openssl-libs libvirt-devel nodejs automake gcc gcc-c++ kernel-devel libcurl-devel sqlite-devel git postgresql-server-devel; \ + git config --global user.name $GIT_COMMITTER_NAME; \ + git config --global user.email $GIT_COMMITTER_EMAIL; \ + mkdir /projects; \ + cd /projects; \ + git clone --depth 1 --branch 3.8-stable https://github.com/theforeman/foreman.git; \ + git clone --depth 1 --branch master https://github.com/theforeman/foreman_virt_who_configure.git + +RUN \ + cd /projects/foreman; \ + echo "gemspec :path => '../foreman_virt_who_configure', :development_group => :dev" > bundler.d/foreman_virt_who_configure.local.rb; \ + cp ../foreman_virt_who_configure/config/database.yml.example config/database.yml; \ + cp ../foreman_virt_who_configure/config/Gemfile.lock.gh_test Gemfile.lock; + +WORKDIR /projects/foreman +RUN \ + bundle config path vendor/bundle; \ + +RUN \ + cd /projects/foreman; \ + rm -rf Gemfile.lock; \ + bundle install --jobs=3 --retry=3 --without journald development console + +COPY ./entrypoint.sh /usr/bin/ + +RUN sed -i s/SCLS=/SCLS=\""$SCLS"\"/g /usr/bin/entrypoint.sh + +RUN chmod +x /usr/bin/entrypoint.sh + +COPY ./run_tests.sh /usr/bin/ +RUN chmod +x /usr/bin/run_tests.sh + +CMD ["/usr/bin/run_tests.sh"] + +ENTRYPOINT ["entrypoint.sh"] diff --git a/.github/images/docker-compose.yaml b/.github/images/docker-compose.yaml new file mode 100644 index 00000000..c4ca130a --- /dev/null +++ b/.github/images/docker-compose.yaml @@ -0,0 +1,19 @@ +# version: "3" +services: + postgres: + image: quay.io/jomitsch/postgres-with-evr + ports: ['5432:5432'] + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + env: + POSTGRES_USER: foreman + POSTGRES_PASSWORD: foreman + foreman: + image: quay.io/shimshtein/tfm_plugin_test:foreman_2_5 + volumes: + - ../../:/projects/foreman_virt_who_configure:Z + depends_on: + - "postgres" diff --git a/.github/images/entrypoint.sh b/.github/images/entrypoint.sh new file mode 100644 index 00000000..e3ad4727 --- /dev/null +++ b/.github/images/entrypoint.sh @@ -0,0 +1,11 @@ +#!/bin/bash +export PATH=~/bin:${GEM_HOME}/bin:${PATH} + +SCLS= + +if [ -x "$(command -v scl_source)" ]; then + source scl_source enable $SCLS +fi + +cd $WORKDIR +exec "$@" diff --git a/.github/images/run_tests.sh b/.github/images/run_tests.sh new file mode 100644 index 00000000..dffd336d --- /dev/null +++ b/.github/images/run_tests.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +bundle install + +# wait for postgres +until PGPASSWORD=$PGPASS psql -h "$PGHOST" -U $PGUSER -c '\q'; do + >&2 echo "Postgres is unavailable - sleeping" + sleep 2 +done + +if [ "$( psql -tAc "SELECT 1 FROM pg_database WHERE datname='foreman-test'" )" = '1' ] +then + echo "Database already exists" +else + bundle exec rails db:create +fi + +if [ "$( psql -tAc "SELECT 1 FROM pg_database WHERE datname='foreman-prod'" )" = '1' ] +then + echo "Database already exists" +else + bundle exec rails db:create RAILS_ENV=production +fi + +bundle exec rails db:migrate + +set -e + +# bundle exec rake foreman_virt_who_configure:rubocop +bundle exec rake test:foreman_virt_who_configure diff --git a/.github/workflows/build_container_pr.yml b/.github/workflows/build_container_pr.yml new file mode 100644 index 00000000..14a49a44 --- /dev/null +++ b/.github/workflows/build_container_pr.yml @@ -0,0 +1,26 @@ +name: Build container for PR +on: + pull_request: + paths: + - '**/.github/**/*' +jobs: + build_test_container: + runs-on: ubuntu-latest + + services: + postgres: + image: quay.io/jomitsch/postgres-with-evr + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + env: + POSTGRES_USER: foreman + POSTGRES_PASSWORD: foreman + + steps: + - name: Checkout the repo + uses: actions/checkout@v2 + - name: Build local dockerfile + uses: ./.github/actions/ diff --git a/.github/workflows/ruby_tests.yml b/.github/workflows/ruby_tests.yml new file mode 100644 index 00000000..c00e34fe --- /dev/null +++ b/.github/workflows/ruby_tests.yml @@ -0,0 +1,63 @@ +name: Ruby tests +on: + push: + branches: [master] + paths-ignore: + - '**/.github/**/*' + pull_request: + branches: [master] + paths-ignore: + - '**/.github/**/*' + +defaults: + run: + working-directory: /projects/foreman + +jobs: + test_ruby: + defaults: + run: + working-directory: /projects/foreman + env: + PGHOST: postgres + PGUSER: foreman + PGPASS: foreman + RAILS_ENV: test + host: postgres + WORKDIR: /projects/foreman + BUNDLE_PATH: vendor/bundle + GIT_COMMITTER_NAME: "gh_actions" + GIT_COMMITTER_EMAIL: "gh_actions@virt_who_configure.foreman" + + runs-on: ubuntu-latest + container: + image: ghcr.io/theforeman/tfm_plugin_test:foreman_3_7 + + services: + postgres: + image: quay.io/jomitsch/postgres-with-evr + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + env: + POSTGRES_USER: foreman + POSTGRES_PASSWORD: foreman + + steps: + - name: Checkout foreman_virt_who_configure repo + uses: actions/checkout@v2 + with: + path: ${{ github.workspace }}/projects/foreman_virt_who_configure + - name: Fix git config + run: | + rm -rf /projects/foreman_virt_who_configure/{app,test,lib} + cp -Rf $GITHUB_WORKSPACE/projects/foreman_virt_who_configure /projects/ + cd /projects/foreman + /usr/bin/entrypoint.sh git config --global user.name $GIT_COMMITTER_NAME + /usr/bin/entrypoint.sh git config --global user.email $GIT_COMMITTER_EMAIL + - name: Run tests suite + run: | + cd /projects/foreman + /usr/bin/entrypoint.sh /usr/bin/run_tests.sh