name: Release # Fires when a v* tag is pushed — including tags created through Gitea's # "New Release" UI. Builds the distributable plugin zip and attaches it to # the release for that tag (creating the release if only a bare tag was # pushed). The attached zip is what UpdateChecker serves to WordPress # sites as the update package. on: push: tags: - 'v*' jobs: release: name: Build and Publish Release runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: '8.3' tools: composer:v2 # A tag that disagrees with the plugin header would make sites see a # phantom update forever (or never see a real one), so fail fast. - name: Verify tag matches plugin version id: meta run: | tag_version="${GITHUB_REF_NAME#v}" header_version="$(sed -nE 's/^[[:space:]]*\*?[[:space:]]*Version:[[:space:]]*([^[:space:]]+).*/\1/p' unsupervised-schedular.php | head -1)" if [ "$tag_version" != "$header_version" ]; then echo "Tag ${GITHUB_REF_NAME} does not match plugin header Version: ${header_version}" >&2 exit 1 fi echo "version=${header_version}" >> "$GITHUB_OUTPUT" - name: Install dependencies run: composer install --prefer-dist --no-progress --no-interaction - name: Run tests run: composer test - name: Build plugin zip run: composer build - name: Publish release with zip asset env: TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | api="${GITHUB_SERVER_URL}/api/v1/repos/${GITHUB_REPOSITORY}" version="${{ steps.meta.outputs.version }}" zip="dist/unsupervised-schedular-${version}.zip" # Pre-release versions (1.2.3-rc.1) are flagged so Gitea's # /releases/latest endpoint — and therefore the update checker — # skips them. prerelease=false case "$version" in *-*) prerelease=true ;; esac # Reuse the release if the tag was created via Gitea's release UI. release_id="$(curl -sS -H "Authorization: token ${TOKEN}" \ "${api}/releases/tags/${GITHUB_REF_NAME}" | jq -r '.id // empty' || true)" if [ -z "$release_id" ]; then release_id="$(curl -fsS -X POST "${api}/releases" \ -H "Authorization: token ${TOKEN}" \ -H 'Content-Type: application/json' \ -d "{\"tag_name\":\"${GITHUB_REF_NAME}\",\"name\":\"${GITHUB_REF_NAME}\",\"prerelease\":${prerelease}}" \ | jq -r '.id')" fi echo "Attaching ${zip} to release ${release_id}" curl -fsS -X POST \ "${api}/releases/${release_id}/assets?name=unsupervised-schedular-${version}.zip" \ -H "Authorization: token ${TOKEN}" \ -F "attachment=@${zip}" > /dev/null