diff --git a/.gitea/workflows/release.yaml b/.gitea/workflows/release.yaml new file mode 100644 index 0000000..cf8bdd2 --- /dev/null +++ b/.gitea/workflows/release.yaml @@ -0,0 +1,62 @@ +name: Release + +on: + release: + types: [ published ] + push: + tags: + - '*' + +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 }} + GITEA_URL: ${{ github.server_url }} + REPO: ${{ github.repository }} + TAG: ${{ github.ref_name }} + run: | + RELEASE_JSON=$(curl -s -H "Authorization: token $GITEA_TOKEN" "$GITEA_URL/api/v1/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\"}" \ + "$GITEA_URL/api/v1/repos/$REPO/releases") + RELEASE_ID=$(echo "$CREATE_RES" | jq -r .id) + fi + + echo "Uploading laps.zip to release ID $RELEASE_ID..." + curl -s -X POST \ + -H "Authorization: token $GITEA_TOKEN" \ + -H "Content-Type: multipart/form-data" \ + -F "attachment=@release/laps.zip" \ + "$GITEA_URL/api/v1/repos/$REPO/releases/$RELEASE_ID/assets?name=laps.zip"