Skip to content

Commit

Permalink
Add GitHub Actions workflow for building the project
Browse files Browse the repository at this point in the history
  • Loading branch information
hidakatsuya committed May 12, 2024
1 parent 708ccf9 commit 1e8484d
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 60 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Build

on:
push:
paths-ignore:
- '*.md'

env:
REDMINE_SRC: redmine-src

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
include:
# - redmine_repository: 'redmine/redmine'
# redmine_version: '5.1-stable'
# redmine_database: 'sqlite3'
# ruby_version: '3.3'
- redmine-repository: 'redmica/redmica'
redmine-version: 'stable-2.4'
redmine-database: 'postgresql'
ruby-version: '3.2'

steps:
- uses: actions/checkout@v4

- uses: ./
with:
path: ${{ env.REDMINE_SRC }}
repository: ${{ matrix.redmine-repository }}
version: ${{ matrix.redmine-version }}
database: ${{ matrix.redmine-database }}
ruby-version: ${{ matrix.ruby-version }}

- run: |
bin/rails test test/unit/news_test.rb
bin/rails test test/system/my_page_test.rb
working-directory: ${{ env.REDMINE_SRC }}
139 changes: 79 additions & 60 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
name: Setup Redmine
description: Setup Redmine or its distribution for testing
author: hidakatsuya

inputs:
repository:
Expand All @@ -14,80 +15,98 @@ inputs:
description: 'Database to use for testing'
required: true
default: 'sqlite3'
ruby-version:
description: 'Ruby version to use for testing'
required: true
path:
description: 'Directory to setup Redmine'
required: true
default: '.'

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;
- uses: actions/cache/restore@v4
id: cache-source-restore
with:
path: .
key: ${{ inputs.repository }}-${{ inputs.version }}-${{ github.sha }}
libnss3-dev;
- uses: actions/checkout@v4
if: steps.cache-source-restore.outputs.cache-hit != 'true'
with:
repository: ${{ inputs.repository }}-${{ github.sha }}
ref: ${{ inputs.version }}
sudo sed -ri 's/(rights)="none" (pattern="PDF")/\1="read" \2/' /etc/ImageMagick-6/policy.xml;
shell: bash
- 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; \
echo GOOGLE_CHROME_OPTS_ARGS="headless,disable-gpu,no-sandbox,disable-dev-shm-usage" >> $GITHUB_ENV
shell: bash
- 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 <<EOS > config/database.yml
test:
adapter: postgresql
database: redmine_test
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 <<EOS > config/database.yml
test:
adapter: sqlite3
database: db/test.sqlite3
EOS
shell: bash
working-directory: ${{ inputs.path }}

- uses: actions/cache/save@v4
id: cache-source
- uses: ruby/setup-ruby@v1
with:
path: .
key: ${{ inputs.repository }}-${{ inputs.version }}-${{ github.sha }}
ruby-version: ${{ inputs.ruby-version }}
bundler-cache: true
working-directory: ${{ inputs.path }}

- run: |
case ${{ inputs.database }} in
sqlite3)
cat <<EOS > config/database.yml
test:
adapter: sqlite3
database: db/test.sqlite3
EOS
;;
postgresql)
cat <<EOF > 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
bin/rails db:create db:migrate
shell: bash
working-directory: ${{ inputs.path }}

0 comments on commit 1e8484d

Please sign in to comment.