|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + |
| 7 | +jobs: |
| 8 | + changes: |
| 9 | + name: Detect changes since last release |
| 10 | + runs-on: ubuntu-latest |
| 11 | + outputs: |
| 12 | + variants: ${{ steps.filter.outputs.changes }} |
| 13 | + steps: |
| 14 | + - name: Checkout code |
| 15 | + uses: actions/checkout@v4 |
| 16 | + with: |
| 17 | + fetch-depth: 0 |
| 18 | + |
| 19 | + - name: Retrieve the previous release version |
| 20 | + id: previous_release |
| 21 | + env: |
| 22 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 23 | + run: | |
| 24 | + # Attempt to get the tag of the second-to-last release |
| 25 | + PREVIOUS_TAG=$(gh release list --limit 2 --json tagName | jq -r '. | select(length > 1) | .[1].tagName') |
| 26 | +
|
| 27 | + if [[ -z "$PREVIOUS_TAG" ]]; then |
| 28 | + echo "No previous release found. Falling back to the first commit." |
| 29 | + REF=$(git rev-list --max-parents=0 HEAD) |
| 30 | + else |
| 31 | + echo "Found previous release: $PREVIOUS_TAG" |
| 32 | + REF=$PREVIOUS_TAG |
| 33 | + fi |
| 34 | +
|
| 35 | + echo "The reference point is: $REF" |
| 36 | + echo "ref=$REF" >> $GITHUB_OUTPUT |
| 37 | +
|
| 38 | + - name: Detect changed variants |
| 39 | + uses: dorny/paths-filter@v3 |
| 40 | + id: filter |
| 41 | + with: |
| 42 | + filters: .github/filters.yml |
| 43 | + base: ${{ steps.previous_release.outputs.ref }} |
| 44 | + |
| 45 | + release: |
| 46 | + name: Release ${{ matrix.variant }} |
| 47 | + needs: changes |
| 48 | + runs-on: ubuntu-latest |
| 49 | + if: needs.changes.outputs.variants != '[]' |
| 50 | + permissions: |
| 51 | + contents: write |
| 52 | + strategy: |
| 53 | + fail-fast: false |
| 54 | + matrix: |
| 55 | + variant: ${{ fromJson(needs.changes.outputs.variants) }} |
| 56 | + steps: |
| 57 | + - name: Checkout code |
| 58 | + uses: actions/checkout@v4 |
| 59 | + |
| 60 | + - name: Set up PHP |
| 61 | + uses: shivammathur/setup-php@v2 |
| 62 | + with: |
| 63 | + php-version: '8.4' |
| 64 | + |
| 65 | + - name: Get composer cache directory |
| 66 | + id: composer-cache |
| 67 | + working-directory: ./publish |
| 68 | + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT |
| 69 | + |
| 70 | + - name: Cache dependencies |
| 71 | + uses: actions/cache@v4 |
| 72 | + with: |
| 73 | + path: ${{ steps.composer-cache.outputs.dir }} |
| 74 | + key: ${{ runner.os }}-composer-${{ hashFiles('publish/composer.lock') }} |
| 75 | + restore-keys: ${{ runner.os }}-composer- |
| 76 | + |
| 77 | + - name: Install dependencies |
| 78 | + working-directory: ./publish |
| 79 | + run: composer install --prefer-dist |
| 80 | + |
| 81 | + - name: Pull image from registry |
| 82 | + run: | |
| 83 | + TAG=$(echo "${{ matrix.variant }}" | sed 's/^php//') |
| 84 | + docker pull ghcr.io/${{ github.repository_owner }}/php:$TAG |
| 85 | +
|
| 86 | + - name: Export artifact |
| 87 | + env: |
| 88 | + DOCKER_REGISTRY: ghcr.io |
| 89 | + DOCKER_IMAGE: ${{ github.repository_owner }}/php |
| 90 | + run: make export/${{ matrix.variant }} |
| 91 | + |
| 92 | + - name: Upload release asset |
| 93 | + env: |
| 94 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 95 | + run: | |
| 96 | + gh release upload ${{ github.event.release.tag_name }} \ |
| 97 | + ./export/${{ matrix.variant }}.zip \ |
| 98 | + --clobber |
| 99 | +
|
| 100 | + - name: Publish to Alibaba Cloud |
| 101 | + env: |
| 102 | + OSS_BUCKET: ${{ secrets.OSS_BUCKET }} |
| 103 | + ACS_ACCESS_KEY_ID: ${{ secrets.ACS_ACCESS_KEY_ID }} |
| 104 | + ACS_ACCESS_KEY_SECRET: ${{ secrets.ACS_ACCESS_KEY_SECRET }} |
| 105 | + run: | |
| 106 | + RELEASE="${{ github.event.release.tag_name }}" \ |
| 107 | + make publish-${{ matrix.variant }} |
0 commit comments