|
| 1 | +name: Checkout and build code |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + TAG: |
| 7 | + description: 'Tag/commit/branch to checkout' |
| 8 | + required: false |
| 9 | + type: string |
| 10 | + default: '' |
| 11 | + PHP_VERSION: |
| 12 | + description: 'The PHP version to use' |
| 13 | + required: true |
| 14 | + type: string |
| 15 | + default: '8.2' |
| 16 | + BUILD_FOR_DEPLOY: |
| 17 | + description: 'Whether to build for deployment immediately or to keep developer tools' |
| 18 | + required: false |
| 19 | + type: boolean |
| 20 | + default: false |
| 21 | + ARTIFACT_NAME: |
| 22 | + description: 'The artifact to deploy' |
| 23 | + required: false |
| 24 | + type: string |
| 25 | + default: 'compressed-code-artifact' |
| 26 | + |
| 27 | +jobs: |
| 28 | + checkout-and-build: |
| 29 | + runs-on: ubuntu-latest |
| 30 | + |
| 31 | + steps: |
| 32 | + - name: Checkout code |
| 33 | + uses: actions/checkout@v3 |
| 34 | + with: |
| 35 | + ref: ${{ inputs.TAG }} |
| 36 | + |
| 37 | + - name: Read PHP version from composer.json (with fallback) |
| 38 | + id: php-version |
| 39 | + run: | |
| 40 | + if ! command -v "jq" &> /dev/null; then |
| 41 | + echo "PHP_VERSION=${{ inputs.PHP_VERSION }}" >> $GITHUB_ENV |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | +
|
| 45 | + # Try to extract PHP version from composer.json |
| 46 | + php_version=$(jq -r '.config.platform.php // empty' composer.json) |
| 47 | + |
| 48 | + # Use a fallback version if not defined |
| 49 | + if [ -z "$php_version" ]; then |
| 50 | + php_version=${{ inputs.PHP_VERSION }} |
| 51 | + fi |
| 52 | +
|
| 53 | + echo "PHP_VERSION=${php_version}" >> $GITHUB_ENV |
| 54 | +
|
| 55 | + - name: Get Composer cache directory |
| 56 | + id: composer-cache |
| 57 | + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT |
| 58 | + |
| 59 | + - name: Set up Composer caching |
| 60 | + uses: actions/cache@v3 |
| 61 | + env: |
| 62 | + cache-name: cache-composer-dependencies |
| 63 | + with: |
| 64 | + path: ${{ steps.composer-cache.outputs.dir }} |
| 65 | + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} |
| 66 | + restore-keys: | |
| 67 | + ${{ runner.os }}-composer- |
| 68 | +
|
| 69 | + - name: Setup PHP environment |
| 70 | + uses: shivammathur/setup-php@v2 |
| 71 | + with: |
| 72 | + php-version: ${{ env.PHP_VERSION }} |
| 73 | + coverage: none |
| 74 | + tools: composer, cs2pr |
| 75 | + |
| 76 | + - name: Install Composer dependencies |
| 77 | + if: ${{ !inputs.BUILD_FOR_DEPLOY }} |
| 78 | + env: |
| 79 | + COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }} |
| 80 | + run: | |
| 81 | + composer install --prefer-dist --no-suggest --no-progress --no-ansi --no-interaction |
| 82 | + composer run build-translations |
| 83 | + echo "vendor/bin" >> $GITHUB_PATH |
| 84 | +x |
| 85 | + - name: Install Composer dependencies for deployment |
| 86 | + if: ${{ inputs.BUILD_FOR_DEPLOY }} |
| 87 | + env: |
| 88 | + COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }} |
| 89 | + run: | |
| 90 | + composer install --prefer-dist --no-suggest --no-progress --no-ansi --no-interaction --no-dev |
| 91 | + composer run build-translations |
| 92 | + echo "vendor/bin" >> $GITHUB_PATH |
| 93 | +
|
| 94 | + - name: Setup Node.js environment |
| 95 | + uses: actions/setup-node@v4 |
| 96 | + with: |
| 97 | + node-version-file: 'package.json' |
| 98 | + check-latest: true |
| 99 | + cache: npm |
| 100 | + |
| 101 | + - name: Install Dependencies |
| 102 | + run: npm ci |
| 103 | + |
| 104 | + - name: Build assets |
| 105 | + run: npm run build |
| 106 | + |
| 107 | + - name: Create code artifact archive |
| 108 | + working-directory: ./ |
| 109 | + run: | |
| 110 | + touch compressed-code-artifact.tar.gz |
| 111 | + tar -czf compressed-code-artifact.tar.gz --exclude=compressed-code-artifact.tar.gz --exclude=.git . |
| 112 | +
|
| 113 | + - name: Upload Artifact |
| 114 | + uses: actions/upload-artifact@v4 |
| 115 | + with: |
| 116 | + name: compressed-code-artifact |
| 117 | + path: compressed-code-artifact.tar.gz |
| 118 | + retention-days: 1 |
| 119 | + overwrite: true |
0 commit comments