From 8aafe0ee40462ae0b31b3f775c7ebebe9d9db15b Mon Sep 17 00:00:00 2001 From: Adam Daley Date: Wed, 6 Dec 2023 20:12:38 +0000 Subject: [PATCH] Rework reusable workflows to use composite actions (#1918) --- .github/workflows/ci.yml | 198 +++++----------------------- .github/workflows/release-build.yml | 90 +++++++++++++ 2 files changed, 126 insertions(+), 162 deletions(-) create mode 100644 .github/workflows/release-build.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7316cc029..7020d6008 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,193 +19,67 @@ jobs: uses: streetsidesoftware/cspell-action@v5 with: incremental_files_only: true - strict: true - verbose: true - php-test-build: - name: 'PHP Build (Dev)' - permissions: - contents: read - needs: [ spellcheck ] - if: ${{ (github.event_name == 'pull_request' && github.event.pull_request.base.repo.id != github.event.pull_request.head.repo.id) || github.event_name == 'push' }} - uses: FOSSBilling/.workflows/.github/workflows/php-build.yml@0a5d7aacd57d9ff6bdfd20d2ec75999cf3c416e4 - with: - php_versions: '["8.1", "8.2", "8.3"]' - upload_artifact_prefix: 'build-test-php' - - prep-test: - name: 'Prepare Test Environment' + php-build-test: + name: 'PHP Build and Test' permissions: contents: read needs: [ spellcheck ] if: ${{ (github.event_name == 'pull_request' && github.event.pull_request.base.repo.id != github.event.pull_request.head.repo.id) || github.event_name == 'push' }} runs-on: ubuntu-latest + strategy: + matrix: + php: [8.1, 8.2, 8.3] steps: - uses: actions/checkout@v4 - - name: 'Create Script to Prepare Test Environment' + - name: 'PHP Build' + uses: FOSSBilling/.workflows/.github/actions/php-build@1c982a733295e2a24abb0221009f2a89741367ff + with: + php-version: ${{ matrix.php }} + + - name: 'Prepare Test Environment' run: | - mkdir /tmp/test_files - echo "cp ./src/config-sample.php ./src/config.php" > /tmp/test_files/prepare-test.sh - echo "mkdir -p ./src/data/{cache,log}" >> /tmp/test_files/prepare-test.sh - echo "echo APP_ENV=test >> $GITHUB_ENV" - - - name: 'Upload Required Test Files' - uses: actions/upload-artifact@v3 + cp ./src/config-sample.php ./src/config.php + mkdir -p ./src/data/{cache,log} + echo APP_ENV=test >> $GITHUB_ENV + + - name: 'PHP Tests (PHPStan and PHPUnit)' + uses: FOSSBilling/.workflows/.github/actions/php-test@1c982a733295e2a24abb0221009f2a89741367ff with: - name: 'test-files' - path: '/tmp/test_files/*' - retention-days: 1 - - php-test: - name: 'PHP Test (Dev)' - permissions: - contents: read - needs: [ php-test-build, prep-test ] - if: ${{ (github.event_name == 'pull_request' && github.event.pull_request.base.repo.id != github.event.pull_request.head.repo.id) || github.event_name == 'push' }} - uses: FOSSBilling/.workflows/.github/workflows/php-test.yml@0a5d7aacd57d9ff6bdfd20d2ec75999cf3c416e4 - with: - download_artifact_prefix: 'build-test-php' - download_test_files: true - php_versions: '["8.1", "8.2", "8.3"]' - phpstan_php_version: '8.3' - phpunit_version: 10 - prepare_test_script: 'prepare-test.sh' - - php-preview-build: - name: 'PHP Build (Preview)' - permissions: - contents: read - needs: [ php-test ] - if: ${{ (github.event_name == 'pull_request' && github.event.pull_request.base.repo.id != github.event.pull_request.head.repo.id) || github.event_name == 'push' }} - uses: FOSSBilling/.workflows/.github/workflows/php-build.yml@0a5d7aacd57d9ff6bdfd20d2ec75999cf3c416e4 - with: - cache_deps: false - composer_args: '--prefer-dist --no-dev --optimize-autoloader' - php_versions: '["8.1"]' - upload_artifact_prefix: 'build-preview-php' - - frontend-preview-build: - name: 'Frontend Assets Build (Preview)' - permissions: - contents: read - needs: [ php-test ] - if: ${{ (github.event_name == 'pull_request' && github.event.pull_request.base.repo.id != github.event.pull_request.head.repo.id) || github.event_name == 'push' }} - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: 'Install Node.js and Enable Caching' - uses: actions/setup-node@v4 - with: - cache: 'npm' - cache-dependency-path: '**/package-lock.json' - node-version: 20 - - - name: 'Install Node.js Dependencies' - run: npm ci - - - name: 'Build Frontend Assets' - run: npm run build - - - name: 'Create Build Archive' - run: | - mkdir -p /tmp/build/themes/{admin_default,huraga}/build - mkdir -p /tmp/build/modules/Wysiwyg/assets - cp -r ./src/themes/admin_default/build/. /tmp/build/themes/admin_default/build/ - cp -r ./src/themes/huraga/build/. /tmp/build/themes/huraga/build/ - cp -r ./src/modules/Wysiwyg/assets/. /tmp/build/modules/Wysiwyg/assets/ - tar -cvf /tmp/build.tar -C /tmp/build/ ./ - - - name: 'Upload Build Archive' - uses: actions/upload-artifact@v3 - with: - if-no-files-found: 'error' - name: 'frontend-preview-build' - path: '/tmp/build.tar' - retention-days: 1 + php-version: ${{ matrix.php }} + phpstan-enable: 'true' + phpstan-php-version: 8.3 + phpunit-enable: 'true' + phpunit-version: 10 preview-build: - name: 'Prepare Preview Build' - permissions: + name: 'Create Preview Release' + permissions: contents: read - needs: [ php-preview-build, frontend-preview-build ] + needs: [ php-build-test ] if: ${{ (github.event_name == 'pull_request' && github.event.pull_request.base.repo.id != github.event.pull_request.head.repo.id) || github.event_name == 'push' }} - runs-on: ubuntu-latest - steps: - - name: 'Download PHP Build (Preview)' - uses: actions/download-artifact@v3 - with: - name: build-preview-php-8.1 - path: /tmp/php-build + uses: ./.github/workflows/release-build.yml + with: + artifact-name: 'preview-build' + preview: true - - name: 'Download Frontend Assets Build (Preview)' - uses: 'actions/download-artifact@v3' - with: - name: frontend-preview-build - path: /tmp/frontend-build - - - name: 'Download Latest Translations' - uses: robinraju/release-downloader@v1.8 - with: - repository: 'FOSSBilling/locale' - latest: true - fileName: 'translations.zip' - out-file-path: './src/locale' - extract: true - - - name: 'Extract Preview Build Archives' - run: | - tar -xvf /tmp/php-build/build.tar ./ - tar -xvf /tmp/frontend-build/build.tar -C ./src - - - name: 'Copy Required Files and Clean-up' - run: | - cp README.md ./src/ - cp LICENSE ./src/ - cp CHANGELOG.md ./src/ - rm ./src/locale/translations.zip - - - name: 'Add Short Commit Hash as the Release Vesion' - run: sed -i s/0.0.1/${GITHUB_SHA::7}/ Version.php - working-directory: ./src/library/FOSSBilling - - - name: 'Add the Sentry DSN' - if: ${{ vars.SENTRY_DSN }} - run: | - d=$'\03' - sed -i "s${d}--replace--this--during--release--process--${d}$SENTRY_DSN$d" SentryHelper.php - working-directory: ./src/library/FOSSBilling - env: - SENTRY_DSN: ${{ vars.SENTRY_DSN }} - - - name: 'Create Preview Build Archive' - run: tar -cvf /tmp/build.tar -C ./src/ ./ - - - name: 'Upload Preview Build Archive' - uses: actions/upload-artifact@v3 - with: - if-no-files-found: 'error' - name: preview-build - path: /tmp/build.tar - retention-days: 1 - upload-preview: - name: 'Upload Downloadable Preview' + name: 'Upload Preview Release' permissions: contents: read needs: [ preview-build ] if: ${{ (github.event_name == 'pull_request' && github.event.pull_request.base.repo.id != github.event.pull_request.head.repo.id) || github.event_name == 'push' }} runs-on: ubuntu-latest steps: - - name: 'Download Preview Build Archive' + - name: 'Download Preview Release Archive' uses: actions/download-artifact@v3 with: name: preview-build path: '/tmp' - - name: 'Extract Preview Build Archive' - run: | + - name: 'Extract Preview Release Archive' + run: | mkdir ./src tar -xvf /tmp/build.tar -C ./src @@ -222,7 +96,7 @@ jobs: if: ${{ github.ref == 'refs/heads/main' }} uses: jakejarvis/s3-sync-action@master with: - args: --acl public-read --follow-symlinks + args: '--acl public-read --follow-symlinks' env: AWS_S3_BUCKET: ${{ secrets.AWS_S3_BUCKET }} AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} @@ -230,10 +104,10 @@ jobs: AWS_S3_ENDPOINT: ${{ secrets.AWS_S3_ENDPOINT }} SOURCE_DIR: './dist' - - name: 'Upload Preview Build to GitHub' + - name: 'Upload Downloadable Preview to GitHub' uses: actions/upload-artifact@v3 with: if-no-files-found: 'error' name: 'FOSSBilling Preview' - path: ./src/* + path: './src/*' retention-days: 14 diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml new file mode 100644 index 000000000..b6e6803ed --- /dev/null +++ b/.github/workflows/release-build.yml @@ -0,0 +1,90 @@ +name: 'Build and Prepare Release Archive' + +on: + workflow_call: + inputs: + artifact-name: + description: 'The artifact name to use when uploading the preview archive.' + default: 'preview-build' + required: false + type: string + preview: + description: 'Whether the release is a preview release or not.' + default: true + required: false + type: boolean + +jobs: + release-build: + name: 'Build and Prepare Release' + permissions: + contents: read + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: 'PHP Build' + uses: FOSSBilling/.workflows/.github/actions/php-build@1c982a733295e2a24abb0221009f2a89741367ff + with: + cache-deps: 'false' + composer-args: '--prefer-dist --no-dev --optimize-autoloader' + php-version: 8.1 + + - name: 'Install Node.js and Enable Caching' + uses: actions/setup-node@v4 + with: + cache: 'npm' + cache-dependency-path: '**/package-lock.json' + node-version: 20 + + - name: 'Install Node.js Dependencies' + run: npm ci + + - name: 'Build Frontend Assets' + run: npm run build + + - name: 'Download Latest Translations' + uses: robinraju/release-downloader@v1.8 + with: + repository: 'FOSSBilling/locale' + latest: true + fileName: 'translations.zip' + out-file-path: './src/locale' + extract: true + + - name: 'Copy Required Files and Clean-up' + run: | + cp README.md ./src/ + cp LICENSE ./src/ + cp CHANGELOG.md ./src/ + rm ./src/locale/translations.zip + + - name: 'Add Short Commit Hash as the Release Vesion' + if: ${{ inputs.preview }} + run: sed -i s/0.0.1/${GITHUB_SHA::7}/ Version.php + working-directory: ./src/library/FOSSBilling + + - name: 'Add the Branch/Tag Name as the Release Version' + if: ${{ inputs.preview == false }} + run: sed -i s/0.0.1/${{ github.ref_name }}/ Version.php + working-directory: ./src/library/FOSSBilling + + - name: 'Add the Sentry DSN' + if: ${{ vars.SENTRY_DSN }} + run: | + d=$'\03' + sed -i "s${d}--replace--this--during--release--process--${d}$SENTRY_DSN$d" SentryHelper.php + working-directory: ./src/library/FOSSBilling + env: + SENTRY_DSN: ${{ vars.SENTRY_DSN }} + + - name: 'Create Release Build Archive' + run: tar -cvf /tmp/build.tar -C ./src/ ./ + + - name: 'Upload Release Build Archive' + uses: actions/upload-artifact@v3 + with: + if-no-files-found: 'error' + name: ${{ inputs.artifact-name }} + path: /tmp/build.tar + retention-days: 1