Release Assets #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release Assets | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| concurrency: | |
| group: release-assets-${{ github.ref_name }} | |
| cancel-in-progress: false | |
| jobs: | |
| release: | |
| name: Build and publish PHAR/package | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: "8.2" | |
| extensions: curl, zip | |
| tools: composer:v2 | |
| coverage: none | |
| - name: Validate composer.json | |
| if: ${{ hashFiles('composer.json') != '' }} | |
| run: composer validate --strict | |
| - name: Install Composer dependencies | |
| if: ${{ hashFiles('composer.json') != '' }} | |
| run: composer install --prefer-dist --no-interaction --no-progress --ignore-platform-req='ext-*' | |
| - name: Run quality checks | |
| if: ${{ hashFiles('composer.json') != '' }} | |
| run: composer run quality | |
| - name: Build PHAR | |
| run: php -d phar.readonly=0 .github/scripts/build-phar.php | |
| - name: Build EasyLibrary package | |
| run: php .github/scripts/build-easylib-package.php | |
| - name: Read release metadata | |
| id: metadata | |
| shell: bash | |
| run: | | |
| source dist/release.env | |
| if [[ "${{ github.event_name }}" == "push" && "${GITHUB_REF_NAME}" != "${TAG}" ]]; then | |
| echo "Tag ${GITHUB_REF_NAME} does not match plugin version ${TAG}" >&2 | |
| exit 1 | |
| fi | |
| echo "name=${NAME}" >> "$GITHUB_OUTPUT" | |
| echo "version=${VERSION}" >> "$GITHUB_OUTPUT" | |
| echo "tag=${TAG}" >> "$GITHUB_OUTPUT" | |
| echo "phar=${PHAR}" >> "$GITHUB_OUTPUT" | |
| echo "easylib=${EASYLIB}" >> "$GITHUB_OUTPUT" | |
| echo "package_manifest=${PACKAGE_MANIFEST}" >> "$GITHUB_OUTPUT" | |
| if [[ "${TAG}" == *"-dev"* ]]; then | |
| echo "prerelease_args=--prerelease" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "prerelease_args=" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Publish GitHub Release assets | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| shell: bash | |
| run: | | |
| TAG="${{ steps.metadata.outputs.tag }}" | |
| TITLE="${{ steps.metadata.outputs.name }} ${{ steps.metadata.outputs.version }}" | |
| PHAR="${{ steps.metadata.outputs.phar }}" | |
| EASYLIB="${{ steps.metadata.outputs.easylib }}" | |
| PACKAGE_MANIFEST="${{ steps.metadata.outputs.package_manifest }}" | |
| PRERELEASE_ARGS="${{ steps.metadata.outputs.prerelease_args }}" | |
| if gh release view "$TAG" >/dev/null 2>&1; then | |
| gh release upload "$TAG" "$PHAR" "$EASYLIB" "$PACKAGE_MANIFEST" dist/checksums.txt --clobber | |
| if [[ -n "$PRERELEASE_ARGS" ]]; then | |
| gh release edit "$TAG" $PRERELEASE_ARGS | |
| fi | |
| elif [[ "${{ github.event_name }}" == "push" ]]; then | |
| gh release create "$TAG" "$PHAR" "$EASYLIB" "$PACKAGE_MANIFEST" dist/checksums.txt \ | |
| --verify-tag \ | |
| --title "$TITLE" \ | |
| $PRERELEASE_ARGS \ | |
| --generate-notes | |
| else | |
| gh release create "$TAG" "$PHAR" "$EASYLIB" "$PACKAGE_MANIFEST" dist/checksums.txt \ | |
| --target "$GITHUB_SHA" \ | |
| --title "$TITLE" \ | |
| $PRERELEASE_ARGS \ | |
| --generate-notes | |
| fi | |
| - name: Verify published PHAR and package | |
| shell: bash | |
| run: | | |
| TAG="${{ steps.metadata.outputs.tag }}" | |
| PHAR="${{ steps.metadata.outputs.phar }}" | |
| ASSET="$(basename "$PHAR")" | |
| URL="https://github.com/${GITHUB_REPOSITORY}/releases/download/${TAG}/${ASSET}" | |
| curl --fail --location --retry 10 --retry-delay 3 --retry-all-errors --output dist/published.phar "$URL" | |
| test "$(sha256sum dist/published.phar | cut -d' ' -f1)" = "$(sha256sum "$PHAR" | cut -d' ' -f1)" | |
| EASYLIB="${{ steps.metadata.outputs.easylib }}" | |
| EASYLIB_ASSET="$(basename "$EASYLIB")" | |
| EASYLIB_URL="https://github.com/${GITHUB_REPOSITORY}/releases/download/${TAG}/${EASYLIB_ASSET}" | |
| curl --fail --location --retry 10 --retry-delay 3 --retry-all-errors --output dist/published.easylib.zip "$EASYLIB_URL" | |
| test "$(sha256sum dist/published.easylib.zip | cut -d' ' -f1)" = "$(sha256sum "$EASYLIB" | cut -d' ' -f1)" | |
| - name: Send Discord release notification | |
| continue-on-error: true | |
| env: | |
| DISCORD_WEBHOOK_URL: ${{ secrets.DISCORD_RELEASE_WEBHOOK_URL }} | |
| NOTIFICATION_KIND: release | |
| RELEASE_NAME: ${{ steps.metadata.outputs.name }} | |
| RELEASE_VERSION: ${{ steps.metadata.outputs.version }} | |
| RELEASE_TAG: ${{ steps.metadata.outputs.tag }} | |
| RELEASE_ASSETS: ${{ steps.metadata.outputs.phar }},${{ steps.metadata.outputs.easylib }},${{ steps.metadata.outputs.package_manifest }},dist/checksums.txt | |
| run: python3 .github/scripts/notify-discord.py release |