diff --git a/.github/actions/dockerbuild/action.yml b/.github/actions/dockerbuild/action.yml new file mode 100644 index 00000000000..1058ab0e8c5 --- /dev/null +++ b/.github/actions/dockerbuild/action.yml @@ -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 diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 9168af32ac1..85c8ba64c59 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -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 diff --git a/.github/workflows/deny-test.yml b/.github/workflows/deny-test.yml index 0b653844a32..8dd5243542d 100644 --- a/.github/workflows/deny-test.yml +++ b/.github/workflows/deny-test.yml @@ -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 diff --git a/.github/workflows/dockerbuild-and-push.yml b/.github/workflows/dockerbuild-and-push.yml new file mode 100644 index 00000000000..5357e4d29fd --- /dev/null +++ b/.github/workflows/dockerbuild-and-push.yml @@ -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:secret@127.0.0.1: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/ diff --git a/.github/workflows/dockerbuild.yml b/.github/workflows/dockerbuild.yml index f7d709b0141..99deaaf2f31 100644 --- a/.github/workflows/dockerbuild.yml +++ b/.github/workflows/dockerbuild.yml @@ -1,148 +1,32 @@ name: Testing dockerbuild on: - push: - paths: - - '**' - - '!*.md' - release: - types: [ published ] + workflow_call: + inputs: + event_name: + required: true + type: string + env: REGISTRY: ghcr.io jobs: dockerbuild: name: dockerbuild - runs-on: ${{ matrix.operating-system }} + runs-on: ubuntu-22.04 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:secret@127.0.0.1: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 + uses: actions/checkout@v4 - - name: Setup PHP - uses: nanasess/setup-php@master + - name: Build docker image + uses: ./.github/actions/dockerbuild 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/ + cache-to: type=gha,mode=max,scope=php-${{ matrix.php }} diff --git a/.github/workflows/e2e-test-throttling.yml b/.github/workflows/e2e-test-throttling.yml index d1c0a633b99..0b77d5dac23 100644 --- a/.github/workflows/e2e-test-throttling.yml +++ b/.github/workflows/e2e-test-throttling.yml @@ -1,17 +1,19 @@ name: E2E test(Throttoling) 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: codeception: name: Codeception diff --git a/.github/workflows/e2e-test.yml b/.github/workflows/e2e-test.yml index 10737841995..48c203217ea 100644 --- a/.github/workflows/e2e-test.yml +++ b/.github/workflows/e2e-test.yml @@ -1,17 +1,20 @@ name: E2E test for EC-CUBE +run-name: e2e-test on: - push: - branches: - - '*' - tags: - - '*' - paths: - - '**' - - '!*.md' - pull_request: - paths: - - '**' - - '!*.md' + workflow_call: +# on: +# push: +# branches: +# - '*' +# tags: +# - '*' +# paths: +# - '**' +# - '!*.md' +# pull_request: +# paths: +# - '**' +# - '!*.md' jobs: codeception: name: Codeception diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000000..785719fb5b9 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,43 @@ +name: CI/CD for EC-CUBE + +on: + push: + branches: + - '*' + tags: + - '*' + paths: + - '**' + - '!*.md' + pull_request: + paths: + - '**' + - '!*.md' +jobs: + dockerbuild: + with: + event_name: ${{ github.event_name }} + uses: ./.github/workflows/dockerbuild.yml + phpstan: + with: + ref_name: ${{ github.ref_name }} + base_ref: ${{ github.base_ref }} + event_name: ${{ github.event_name }} + owner: ${{ github.repository_owner }} + needs: [ dockerbuild ] + uses: ./.github/workflows/phpstan.yml + # unit-tests: + # needs: [ PHPStan ] + # uses: ./.github/workflows/unit-tests.yml + # e2e-test: + # needs: [ PHPStan ] + # uses: ./.github/workflows/e2e-test.yml + # plugin-test: + # needs: [ PHPStan ] + # uses: ./.github/workflows/plugin-test.yml + # e2e-test-throttling: + # needs: [ e2e-test ] + # uses: ./.github/workflows/e2e-test-throttling.yml + # deny-test: + # needs: [ UnitTest ] + # uses: ./.github/workflows/deny-test.yml diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 2e67bac37fa..1d469095d43 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -1,35 +1,49 @@ name: PHPStan -on: - push: - branches: - - '*' - tags: - - '*' - paths: - - '**' - - '!*.md' - pull_request: - paths: - - '**' - - '!*.md' +run-name: PHPStan +on: + workflow_call: + inputs: + ref_name: + required: false + type: string + base_ref: + required: false + type: string + event_name: + required: true + type: string + owner: + required: true + type: string jobs: phpstan: name: PHPStan - runs-on: ubuntu-latest - steps: - name: "Checkout" - uses: actions/checkout@v2 + uses: actions/checkout@v4 - - name: Setup PHP - uses: nanasess/setup-php@master + - name: Build docker image + uses: ./.github/actions/dockerbuild with: - php-version: '8.1' - - - name: Initialize Composer - uses: ./.github/actions/composer + php-version: '8.3' - - name: PHPStan - run: vendor/bin/phpstan analyze src/ --error-format=github + - name: Setup environment + env: + REF_NAME: ${{ inputs.ref_name }} + BASE_REF: ${{ inputs.base_ref }} + EVENT_NAME: ${{ inputs.event_name }} + OWNER: ${{ inputs.owner }} + run: | + echo "COMPOSE_FILE=docker-compose.yml:docker-compose.pgsql.yml:docker-compose.dev.yml" >> $GITHUB_ENV + echo "IMAGE_NAME=${OWNER,,}/ec-cube-php" >> $GITHUB_ENV + if [ $EVENT_NAME = "pull_request" ]; then + echo "TAG=8.3-apache-${BASE_REF}" >> $GITHUB_ENV + else + echo "TAG=8.3-apache-${REF_NAME}" >> $GITHUB_ENV + fi + - run: | + docker compose up -d --wait + docker compose exec -T ec-cube composer install + - run: docker compose exec -T ec-cube php vendor/bin/phpstan --no-progress analyze src/ --error-format=github diff --git a/.github/workflows/plugin-test.yml b/.github/workflows/plugin-test.yml index 084834ab1ae..80a6c9553fc 100644 --- a/.github/workflows/plugin-test.yml +++ b/.github/workflows/plugin-test.yml @@ -1,17 +1,19 @@ name: Plugin test 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: plugin-install: name: Plugin install diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 18f572d0c50..49180b7f7fb 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -1,17 +1,20 @@ name: Unit test for EC-CUBE +run-name: UnitTest on: - push: - branches: - - '*' - tags: - - '*' - paths: - - '**' - - '!*.md' - pull_request: - paths: - - '**' - - '!*.md' + workflow_call: +# on: +# push: +# branches: +# - '*' +# tags: +# - '*' +# paths: +# - '**' +# - '!*.md' +# pull_request: +# paths: +# - '**' +# - '!*.md' jobs: phpunit: name: PHPUnit