name: Release on: release: types: [ published ] push: tags: - '*' permissions: contents: write jobs: upload-asset: runs-on: ubuntu-latest container: image: php:7.4-cli steps: - name: Install system dependencies run: | apt-get update -qq apt-get install -y -qq git unzip zip curl jq curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer - uses: actions/checkout@v3 - name: Build release zip run: | mkdir -p release/laps git archive HEAD | tar -x -C release/laps cd release/laps composer config platform.php 7.4 composer remove composer/installers --no-update composer update --no-dev --optimize-autoloader cd .. zip -q -r laps.zip laps rm -rf laps - name: Upload zip to Gitea Release env: GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }} API_URL: ${{ github.api_url }} SERVER_URL: ${{ github.server_url }} REPO: ${{ github.repository }} TAG: ${{ github.ref_name }} run: | if [ -z "$API_URL" ]; then API_URL="${SERVER_URL}/api/v1" fi echo "Target API: $API_URL/repos/$REPO" RELEASE_JSON=$(curl -s -H "Authorization: token $GITEA_TOKEN" "$API_URL/repos/$REPO/releases/tags/$TAG") RELEASE_ID=$(echo "$RELEASE_JSON" | jq -r .id) if [ "$RELEASE_ID" = "null" ] || [ -z "$RELEASE_ID" ]; then echo "Creating release for tag $TAG..." CREATE_RES=$(curl -s -X POST \ -H "Authorization: token $GITEA_TOKEN" \ -H "Content-Type: application/json" \ -d "{\"tag_name\":\"$TAG\",\"name\":\"$TAG\",\"body\":\"Release $TAG\"}" \ "$API_URL/repos/$REPO/releases") RELEASE_ID=$(echo "$CREATE_RES" | jq -r .id) fi echo "Uploading laps.zip to release ID $RELEASE_ID..." curl -s -f -X POST \ -H "Authorization: token $GITEA_TOKEN" \ -H "Content-Type: multipart/form-data" \ -F "attachment=@release/laps.zip" \ "$API_URL/repos/$REPO/releases/$RELEASE_ID/assets?name=laps.zip"