From 20b62314d5fb7162b5c626a22f30df0c3f300bc3 Mon Sep 17 00:00:00 2001 From: Katsuya Hidaka Date: Sun, 12 May 2024 17:58:27 +0900 Subject: [PATCH] Add GitHub Actions workflow for building the project --- .github/workflows/build.yml | 32 +++++++++ action.yml | 126 +++++++++++++++++++----------------- 2 files changed, 97 insertions(+), 61 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..1bd3af8 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,32 @@ +name: Build + +on: + push: + paths-ignore: + - '*.md' + +env: + REDMINE_SRC: redmine-src + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - uses: ./ + with: + path: ${{ env.REDMINE_SRC }} + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.3' + bundler-cache: true + working-directory: ${{ env.REDMINE_SRC }} + + - run: | + bin/rails db:prepare + bin/rails test test/unit/news_test.rb + bin/rails test test/system/my_page_test.rb + working-directory: ${{ env.REDMINE_SRC }} diff --git a/action.yml b/action.yml index 6b0bfe0..b449642 100644 --- a/action.yml +++ b/action.yml @@ -1,7 +1,12 @@ name: Setup Redmine description: Setup Redmine or its distribution for testing +author: hidakatsuya inputs: + path: + description: 'Directory to setup Redmine' + required: true + default: '.' repository: description: 'Redmine repository to setup' required: true @@ -18,76 +23,75 @@ inputs: runs: using: composite - pre-if: ${{ runner.os == 'Linux' }} - - services: - chrome: - image: selenium/standalone-chrome - ports: - - 4444:4444 - postgres: - image: postgres:14 + steps: + - run: | + echo "$GITHUB_ACTION_PATH" >> $GITHUB_PATH + echo "REDMINE_SRC=redmine-src" >> $GITHUB_ENV + shell: bash env: - POSTGRES_PASSWORD: postgres - ports: - - 5432:5432 + GITHUB_ACTION_PATH: ${{ github.action_path }} + + - run: | + echo "RAILS_ENV=test" >> $GITHUB_ENV + shell: bash + + - uses: actions/checkout@v4 + with: + repository: ${{ inputs.repository }} + ref: ${{ inputs.version }} + path: ${{ inputs.path }} - steps: - run: | - apt-get update; \ - apt-get install -y --no-install-recommends \ + sudo apt-get update; \ + sudo apt-get install -y --no-install-recommends \ sudo build-essential curl wget vim \ bzr git mercurial subversion cvs \ ghostscript \ gsfonts \ imagemagick libmagick++-dev \ - libsqlite3-dev \ - libpgsql-dev \ - libnss3-dev \ - ; \ - rm -rf /var/lib/apt/lists/*; \ - sed -ri 's/(rights)="none" (pattern="PDF")/\1="read" \2/' /etc/ImageMagick-6/policy.xml; + libnss3-dev; - - uses: actions/cache/restore@v4 - id: cache-source-restore - with: - path: . - key: ${{ inputs.repository }}-${{ inputs.version }}-${{ github.sha }} + sudo sed -ri 's/(rights)="none" (pattern="PDF")/\1="read" \2/' /etc/ImageMagick-6/policy.xml; + shell: bash - - uses: actions/checkout@v4 - if: steps.cache-source-restore.outputs.cache-hit != 'true' - with: - repository: ${{ inputs.repository }}-${{ github.sha }} - ref: ${{ inputs.version }} + - run: | + wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \ + echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list && \ + apt-get update && apt-get install -y --no-install-recommends google-chrome-stable; \ - - uses: actions/cache/save@v4 - id: cache-source - with: - path: . - key: ${{ inputs.repository }}-${{ inputs.version }}-${{ github.sha }} + echo GOOGLE_CHROME_OPTS_ARGS="headless,disable-gpu,no-sandbox,disable-dev-shm-usage" >> $GITHUB_ENV + shell: bash - - run: | - case ${{ inputs.database }} in - sqlite3) - cat < config/database.yml - test: - adapter: sqlite3 - database: db/test.sqlite3 - EOS - ;; - postgresql) - cat < config/database.yml - test: - adapter: postgresql - encoding: utf8 - host: postgres - port: 5432 - username: postgres - password: postgres - EOS - ;; - *) - echo "Unknown database: ${{ inputs.database }}" - exit 1 - ;; - esac + - if: ${{ inputs.database == 'postgresql' }} + run: | + sudo apt-get install libpq-dev + + docker run \ + --name redmine-postgres \ + -e POSTGRES_PASSWORD=postgres \ + -p 5432:5432 \ + -d postgres:14 + + cat < config/database.yml + test: + adapter: postgresql + encoding: utf8 + host: localhost + port: 5432 + username: postgres + password: postgres + EOS + shell: bash + working-directory: ${{ inputs.path }} + + - if: ${{ inputs.database == 'sqlite3' }} + run: | + sudo apt-get install libsqlite3-dev + + cat < config/database.yml + test: + adapter: sqlite3 + database: db/test.sqlite3 + EOS + shell: bash + working-directory: ${{ inputs.path }}