Skip to content

Commit

Permalink
Use Reuseable workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
nanasess committed Apr 17, 2024
1 parent e44c828 commit 66ecbef
Show file tree
Hide file tree
Showing 11 changed files with 375 additions and 223 deletions.
55 changes: 55 additions & 0 deletions .github/actions/dockerbuild/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: 'Docker build action'
description: 'Builds a Docker image for PHP'
inputs:
php-version:
description: 'PHP version to build'
default: '8.1'
required: true
registry:
description: 'Docker registry to push to'
default: 'ghcr.io'
required: true
cache-to:
description: 'Add the Docker build layer to the cache'
default: ~
required: false

runs:
using: "composite"
steps:
- name: downcase REPO
shell: 'bash'
run: |
echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}-php" >> ${GITHUB_ENV}
## Used when creating multi-platform images
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v2
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v2
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ inputs.registry }}/${{ env.IMAGE_NAME }}
tags: |
# set latest tag for default branch
type=raw,value=${{ inputs.php-version }}-apache,prefix=,enable={{is_default_branch}}
type=ref,event=branch,prefix=${{ inputs.php-version }}-apache-
type=ref,event=tag,prefix=${{ inputs.php-version }}-apache-
type=ref,event=pr,prefix=${{ inputs.php-version }}-apache-pr-
type=semver,pattern={{raw}}
type=sha,format=short
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build and export to Docker
uses: docker/build-push-action@v5
with:
context: .
load: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha,scope=php-${{ inputs.php-version }}
cache-to: ${{ inputs.cache-to }}
build-args: TAG=${{ inputs.php-version }}-apache
25 changes: 13 additions & 12 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
name: Coverage
on:
push:
branches:
- '*'
tags:
- '*'
paths:
- '**'
- '!*.md'
pull_request:
paths:
- '**'
- '!*.md'
workflow_call:
# push:
# branches:
# - '*'
# tags:
# - '*'
# paths:
# - '**'
# - '!*.md'
# pull_request:
# paths:
# - '**'
# - '!*.md'
jobs:
phpunit:
name: PHPUnit
Expand Down
26 changes: 14 additions & 12 deletions .github/workflows/deny-test.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
name: Deny check for EC-CUBE
on:
push:
branches:
- '*'
tags:
- '*'
paths:
- '**'
- '!*.md'
pull_request:
paths:
- '**'
- '!*.md'
workflow_call:
# on:
# push:
# branches:
# - '*'
# tags:
# - '*'
# paths:
# - '**'
# - '!*.md'
# pull_request:
# paths:
# - '**'
# - '!*.md'
jobs:
deploy:
name: Deny check
Expand Down
148 changes: 148 additions & 0 deletions .github/workflows/dockerbuild-and-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
name: Docker build and push
on:
push:
paths:
- '**'
- '!*.md'
release:
types: [ published ]
env:
REGISTRY: ghcr.io

jobs:
dockerbuild:
name: dockerbuild
runs-on: ${{ matrix.operating-system }}
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
operating-system: [ ubuntu-22.04 ]
php: [ '8.1', '8.2', '8.3' ]
db: [ pgsql ]
group: [ admin01 ]
include:
- db: pgsql
database_url: postgres://dbuser:[email protected]:15432/eccubedb
database_server_version: 14
- group: admin01
app_env: 'codeception'
- php: '8.1'
tag: '8.1-apache'
- php: '8.2'
tag: '8.2-apache'
- php: '8.3'
tag: '8.3-apache'

steps:
- name: downcase REPO
run: |
echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}-php" >> ${GITHUB_ENV}
- name: Checkout
uses: actions/checkout@master
## Used when creating multi-platform images
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v2
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v2

- name: Setup PHP
uses: nanasess/setup-php@master
with:
php-version: ${{ matrix.php }}

- name: Initialize Composer
uses: ./.github/actions/composer

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
# set latest tag for default branch
type=raw,value=${{ matrix.php }}-apache,prefix=,enable={{is_default_branch}}
type=ref,event=branch,prefix=${{ matrix.php }}-apache-
type=ref,event=tag,prefix=${{ matrix.php }}-apache-
type=ref,event=pr,prefix=${{ matrix.php }}-apache-pr-
- name: Build and export to Docker
uses: docker/build-push-action@v3
with:
context: .
load: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: TAG=${{ matrix.tag }}

- name: Setup to EC-CUBE
env:
APP_ENV: ${{ matrix.app_env }}
DATABASE_URL: ${{ matrix.database_url }}
DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }}
REGISTRY: ${{ env.REGISTRY }}
IMAGE_NAME: ${{ env.IMAGE_NAME }}
TAG: ${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
run: |
docker compose -f docker-compose.yml -f docker-compose.pgsql.yml up -d --wait
sed -i 's!APP_ENV: "dev"!APP_ENV: "prod"!g' docker-compose.yml
sed -i 's!APP_DEBUG: 1!APP_DEBUG: 0!g' docker-compose.yml
docker compose -f docker-compose.yml -f docker-compose.pgsql.yml up -d --wait
- name: setup-chromedriver
uses: nanasess/setup-chromedriver@master

- name: Run chromedriver
run: |
export DISPLAY=:99
chromedriver --url-base=/wd/hub &
echo ">>> Started chrome-driver"
sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 &
echo ">>> Started xvfb"
- name: Codeception
env:
APP_ENV: ${{ matrix.app_env }}
DATABASE_URL: ${{ matrix.database_url }}
DATABASE_SERVER_VERSION: ${{ matrix.database_server_version }}
MAILER_URL: 'smtp://127.0.0.1:1025'
GROUP: ${{ matrix.group }}
SYMFONY_DEPRECATIONS_HELPER: weak
run: |
echo "APP_ENV=${APP_ENV}" > .env
sed -i "s|%GITHUB_WORKSPACE%|${GITHUB_WORKSPACE}|g" codeception/_envs/github_action_docker.yml
vendor/bin/codecept -vvv run acceptance --env chrome,github_action_docker -g ${GROUP} --html report.html
## see https://docs.github.com/ja/packages/managing-github-packages-using-github-actions-workflows/publishing-and-installing-a-package-with-github-actions#publishing-a-package-using-an-action

- name: Push Docker image
uses: docker/build-push-action@v3
if: success()
with:
context: .
push: true
# platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: TAG=${{ matrix.tag }}

- name: Upload evidence
if: failure()
uses: actions/upload-artifact@v2
with:
name: codeception-${{ matrix.group }}-evidence
path: codeception/_output/
- name: Upload logs
if: failure()
uses: actions/upload-artifact@v2
with:
name: codeception-${{ matrix.group }}-logs
path: var/log/
Loading

0 comments on commit 66ecbef

Please sign in to comment.