-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
93e7f41
commit 50a6d32
Showing
1 changed file
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/[email protected] | ||
|
||
- 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 |