Merge pull request #1202 from gotoeveryone/dependabot/npm_and_yarn/sa… #2187
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build | |
on: [push] | |
jobs: | |
code_check_backend: | |
runs-on: ubuntu-latest | |
container: | |
image: ghcr.io/gotoeveryone/composer-php:8.2 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Cache modules | |
uses: actions/cache@v4 | |
id: vendor_cache | |
with: | |
path: vendor | |
key: ${{ runner.OS }}-vendor-${{ hashFiles('**/composer.lock') }} | |
- name: Install dependencies | |
if: ${{ steps.vendor_cache.outputs.cache-hit != 'true' }} | |
run: composer install | |
- name: Execute code check | |
run: composer cs-check | |
code_check_frontend: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20.17" | |
cache: "npm" | |
cache-dependency-path: package-lock.json | |
- name: Install dependencies | |
run: npm ci | |
- name: Execute code check | |
run: npm run lint | |
test_backend: | |
timeout-minutes: 3 | |
runs-on: ubuntu-latest | |
# 本来はこの方法でテストを実行したいが、service として立ち上げる MySQL は非 ASCII 文字に対応しておらずエラーになるため一旦断念 | |
# container: | |
# image: ghcr.io/gotoeveryone/composer-php:7.4 | |
# services: | |
# database: | |
# image: mysql:5.7 | |
# ports: | |
# - 3306:3306 | |
# env: | |
# MYSQL_DATABASE: 'gotea_test' | |
# MYSQL_ALLOW_EMPTY_PASSWORD: 'yes' | |
# options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 | |
env: | |
DB_TEST_HOST: '127.0.0.1' | |
DB_TEST_PORT: 33306 | |
DB_TEST_USERNAME: 'root' | |
DB_TEST_PASSWORD: '' | |
DB_TEST_NAME: 'gotea_test' | |
DB_TEST_ENCODING: 'utf8mb4' | |
DB_TEST_TIMEZONE: 'Asia/Tokyo' | |
SECURITY_SALT: ${{ secrets.SECURITY_SALT }} | |
TZ: Asia/Tokyo | |
SENTRY_DSN: '' | |
steps: | |
- name: Set up MySQL | |
run: > | |
docker run \ | |
-e MYSQL_DATABASE=${DB_TEST_NAME} \ | |
-e MYSQL_ALLOW_EMPTY_PASSWORD=yes \ | |
-d \ | |
-p ${DB_TEST_PORT}:3306 \ | |
mysql:5.7 mysqld --character-set-server=${DB_TEST_ENCODING} --collation-server=${DB_TEST_ENCODING}_general_ci | |
- uses: actions/checkout@v4 | |
- name: Setup PHP | |
uses: shivammathur/setup-php@v2 | |
with: | |
php-version: 8.1 | |
extensions: zip, intl, pdo_mysql | |
ini-values: xdebug.mode="develop" | |
- name: Wait for MySQL | |
run: | | |
while ! mysqladmin ping --host=${DB_TEST_HOST} --port ${DB_TEST_PORT} --silent; do | |
sleep 1 | |
done | |
- name: Cache modules | |
uses: actions/cache@v4 | |
id: vendor_cache | |
with: | |
path: vendor | |
key: ${{ runner.OS }}-vendor-${{ hashFiles('**/composer.lock') }} | |
- name: Install dependencies | |
if: ${{ steps.vendor_cache.outputs.cache-hit != 'true' }} | |
run: composer install | |
- name: Execute setup | |
if: ${{ steps.vendor_cache.outputs.cache-hit == 'true' }} | |
run: composer setup | |
- name: Execute test | |
run: composer test | |
test_frontend: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20.17" | |
cache: "npm" | |
cache-dependency-path: package-lock.json | |
- name: Install dependencies | |
run: npm ci | |
- name: Execute code check | |
run: npm test | |
deploy: | |
if: ${{ github.ref == 'refs/heads/main' }} | |
env: | |
TAR_NAME: 'gotea_${{ github.run_number }}.tar.gz' | |
SHELL_DEST_PATH: '~/deploy_${{ github.run_number }}.sh' | |
runs-on: ubuntu-latest | |
needs: | |
- code_check_backend | |
- code_check_frontend | |
- test_backend | |
- test_frontend | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install SSH Key | |
uses: shimataro/ssh-key-action@v2 | |
with: | |
key: ${{ secrets.SECRET_KEY }} | |
name: id_rsa-target | |
known_hosts: ${{ secrets.SSH_KNOWN_HOSTS }} | |
config: | | |
Host * | |
StrictHostKeyChecking no | |
UserKnownHostsFile=/dev/null | |
Host target | |
HostName ${{ secrets.SSH_HOST }} | |
User ${{ secrets.SSH_USER }} | |
Port ${{ secrets.SSH_PORT }} | |
IdentityFile ~/.ssh/id_rsa-target | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20.17" | |
cache: "npm" | |
cache-dependency-path: package-lock.json | |
- name: Install dependencies | |
run: npm ci | |
- name: Build assets | |
run: npm run prod | |
- name: Transfer modules | |
run: | | |
tar czf ~/${TAR_NAME} bin/ config/ plugins/ resources/ src/ templates/ webroot/ composer.json composer.lock | |
scp -r ~/${TAR_NAME} target:~/ | |
scp ./shell/deploy.sh target:${SHELL_DEST_PATH} | |
- name: Deploy modules | |
run: ssh target "${SHELL_DEST_PATH} ${TAR_NAME} gotea && rm -f ${SHELL_DEST_PATH}" | |
notify: | |
if: ${{ always() && !contains(github.ref, 'dependabot/') }} | |
needs: | |
- deploy | |
runs-on: ubuntu-latest | |
steps: | |
- uses: technote-space/workflow-conclusion-action@v3 | |
- name: Notify to Slack | |
uses: 8398a7/action-slack@v3 | |
with: | |
status: ${{ env.WORKFLOW_CONCLUSION }} | |
author_name: GitHub Actions | |
fields: message,ref | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} |