From 50a6d322c27329a4d53e26ed96804f468e052155 Mon Sep 17 00:00:00 2001 From: Halil Beycan <50718965+BeycanDeveloper@users.noreply.github.com> Date: Thu, 4 Jan 2024 21:50:39 +0800 Subject: [PATCH] . --- .github/workflows/release.yaml | 93 ++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 .github/workflows/release.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..b63fe1f --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,93 @@ +name: Create Release and Upload Zip + +# workflow_dispatch: if you want to create a release manually +on: #workflow_dispatch + release: + types: [released] + branches: + - master + # created: if you want to create a release for every tag + # prereleased: if you want to create a release for prerelease + # published: if you want to create a release for every tag that is published + +env: + RELEASE_ID: 10 + WP_MIN_VERSION: 5.0 + WP_TESTED_VERSION: 6.4.2 + RELEASE_ZIP_NAME: cryptopay-donation.zip + IGNORED_FILES_LIST: | + .git + .github + .vscode + .gitignore + .gitattributes + phpcs.xml + +jobs: + release: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2.4.0 + + - name: Get release assets + run: | + RELEASE_INFO=$(curl -L -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Content-Type: application/json" \ + "https://api.github.com/repos/${{ github.repository }}/releases/latest") + + ASSET_URL=$(echo "$RELEASE_INFO" | jq -r --arg releaseZip "$RELEASE_ZIP_NAME" '.assets[] | select(.name == $releaseZip) | .url') + + if [ -n "$ASSET_URL" ]; then + echo "ASSET_URL=$ASSET_URL" >> $GITHUB_ENV + else + echo "ASSET_URL=null" >> $GITHUB_ENV + fi + + - name: Use existing or create and upload Zip + run: | + ASSET_URL=${{ env.ASSET_URL }} + + if [ "$ASSET_URL" != "null" ]; then + echo "Release asset found: $ASSET_URL" + curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -H "Accept: application/octet-stream" -o "$RELEASE_ZIP_NAME" -L "$ASSET_URL" + + unzip -t "$RELEASE_ZIP_NAME" + if [ $? -ne 0 ]; then + echo "Zip file is corrupted." + fi + else + echo "No matching release asset found for $RELEASE_ZIP_NAME. Creating a new one..." + + IGNORED_FILES=$(echo "$IGNORED_FILES_LIST" | tr '\n' ' ') + git ls-files | grep -v -E "$(echo $IGNORED_FILES | tr ' ' '|')" | zip -@ $RELEASE_ZIP_NAME + + upload_url=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Content-Type: application/json" \ + "https://api.github.com/repos/${{ github.repository }}/releases/${{ github.event.release.id }}" | jq -r '.upload_url') + + upload_url="${upload_url%\{*}" # Remove the query parameters from upload_url + + curl -X POST \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Content-Type: application/zip" \ + --data-binary @"$RELEASE_ZIP_NAME" \ + "$upload_url?name=$RELEASE_ZIP_NAME" + fi + + - name: Update Updater release + run: | + version=$(echo "${{ github.event.release.tag_name }}") + changelog=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + "https://api.github.com/repos/${{ github.repository }}/releases/${{ github.event.release.id }}" | jq -r '.body') + + curl -X POST \ + -F "version=${version}" \ + -F "changelog=${changelog}" \ + -F "releaseId=$RELEASE_ID" \ + -F "wpMinVersion=$WP_MIN_VERSION" \ + -F "wpTestedVersion=$WP_TESTED_VERSION" \ + -F "file=@$RELEASE_ZIP_NAME;type=application/zip" \ + -H "Authorization: Bearer ${{ secrets.UPDATER_API_SECRET }}" \ + https://updater.beycanpress.net/?rest_route=/fx-api/update-releases