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 20b6231
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 61 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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 }}
126 changes: 65 additions & 61 deletions action.yml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 <<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
- 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
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 }}

0 comments on commit 20b6231

Please sign in to comment.