Skip to content

Check and Duplicate Phaito App and YML file #152

Check and Duplicate Phaito App and YML file

Check and Duplicate Phaito App and YML file #152

name: Check and Duplicate Phaito App and YML file
on:
release:
types: [published]
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
jobs:
check-and-duplicate:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Get latest release
id: get_release
uses: octokit/[email protected]
with:
route: GET /repos/{owner}/{repo}/releases/latest
owner: Image-Salon
repo: phaito-electron-updates
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Extract data from release
id: extract_data
env:
DATA: ${{ steps.get_release.outputs.data }}
run: |
printf '%s\n' "$DATA" > release_data.json
tag_name=$(jq -r '.tag_name' release_data.json)
version="${tag_name#v}"
echo "VERSION=$version" >> $GITHUB_ENV
release_id="$(jq -r '.id' release_data.json)"
echo "RELEASE_ID=$release_id" >> $GITHUB_ENV
assets_url="$(jq -r '.assets_url' release_data.json)"
echo "ASSETS_URL=$assets_url" >> $GITHUB_ENV
upload_url="$(jq -r '.upload_url' release_data.json | sed 's/{.*}//')"
echo "UPLOAD_URL=$upload_url" >> $GITHUB_ENV
- name: Get version
env:
VERSION: ${{ env.VERSION }}
RELEASE_ID: ${{ env.RELEASE_ID }}
ASSETS_URL: ${{ env.ASSETS_URL }}
UPLOAD_URL: ${{ env.UPLOAD_URL }}
run: |
echo "VERSION: $VERSION"
echo "RELEASE_ID: $RELEASE_ID"
echo "ASSETS_URL: $ASSETS_URL"
echo "UPLOAD_URL: $UPLOAD_URL"
- name: Check Phaito.exe
id: check_phaito_exe
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ASSETS_URL: ${{ env.ASSETS_URL }}
PHATO_EXE_EXISTS: ${{ env.PHATO_EXE_EXISTS }}
run: |
assets=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "$ASSETS_URL")
PHATO_EXE_EXISTS=false
if echo "$assets" | jq -e '.[] | select(.name == "Phaito.exe")'; then
PHATO_EXE_EXISTS=true
fi
echo "PHATO_EXE_EXISTS=$PHATO_EXE_EXISTS" >> $GITHUB_ENV
echo "PHATO_EXE_EXISTS : $PHATO_EXE_EXISTS"
- name: Check and duplicate Phaito.exe
if: env.PHATO_EXE_EXISTS == 'false'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ASSETS_URL: ${{ env.ASSETS_URL }}
UPLOAD_URL: ${{ env.UPLOAD_URL }}
PHATO_EXE_EXISTS: ${{ env.PHATO_EXE_EXISTS }}
run: |
assets=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "$ASSETS_URL")
PHATO_EXE_EXISTS=false
if ! echo "$assets" | jq -e '.[] | select(.name == "Phaito.exe")'; then
file_to_duplicate=$(echo "$assets" | jq -r '.[] | select(.name | test("^Phaito_.*\\.exe$")) | .browser_download_url')
if [ -n "$file_to_duplicate" ]; then
# Download the file
curl -L -o Phaito.exe "$file_to_duplicate"
# Upload the file
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary @"Phaito.exe" \
"$UPLOAD_URL?name=Phaito.exe&label=Phaito.exe"
PHATO_EXE_EXISTS=true
fi
fi
echo "PHATO_EXE_EXISTS=$PHATO_EXE_EXISTS" >> $GITHUB_ENV
echo "PHATO_EXE_EXISTS : $PHATO_EXE_EXISTS"
- name: Check latest.yml
id: check_latest_yml
if: env.PHATO_EXE_EXISTS == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ASSETS_URL: ${{ env.ASSETS_URL }}
PHATO_EXE_EXISTS: ${{ env.PHATO_EXE_EXISTS }}
run: |
assets=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "$ASSETS_URL")
PHATO_LATEST_YML_EXISTS=false
if echo "$assets" | jq -e '.[] | select(.name == "latest-mac.yml")'; then
PHATO_LATEST_YML_EXISTS=true
fi
echo "PHATO_LATEST_YML_EXISTS=$PHATO_LATEST_YML_EXISTS" >> $GITHUB_ENV
echo "PHATO_EXE_EXISTS : ${{ env.PHATO_EXE_EXISTS }}"
echo "PHATO_LATEST_YML_EXISTS : $PHATO_LATEST_YML_EXISTS"
- name: Generate latest.yml
if: env.PHATO_EXE_EXISTS == 'true' && env.PHATO_LATEST_YML_EXISTS == 'false'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ASSETS_URL: ${{ env.ASSETS_URL }}
VERSION: ${{ env.VERSION }}
PHATO_EXE_EXISTS: ${{ env.PHATO_EXE_EXISTS }}
PHATO_LATEST_YML_EXISTS: ${{ env.PHATO_LATEST_YML_EXISTS }}
run: |
assets=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "$ASSETS_URL")
if ! echo "$assets" | jq -e '.[] | select(.name == "latest.yml")'; then
file_to_duplicate_exe=$(echo "$assets" | jq -r '.[] | select(.name | test("^Phaito_.*\\.exe$")) | .browser_download_url')
if [ -n "$file_to_duplicate_exe" ]; then
# Download the file
curl -L -o "Phaito_${VERSION}.exe" "$file_to_duplicate_exe"
fi
node scripts/generate-latest-yml.js "${VERSION}" "win32"
fi
- name: Upload latest.yml
if: env.PHATO_EXE_EXISTS == 'true' && env.PHATO_LATEST_YML_EXISTS == 'false'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
UPLOAD_URL: ${{ env.UPLOAD_URL }}
PHATO_EXE_EXISTS: ${{ env.PHATO_EXE_EXISTS }}
PHATO_LATEST_YML_EXISTS: ${{ env.PHATO_LATEST_YML_EXISTS }}
run: |
if [ -f "latest.yml" ]; then
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: text/yaml" \
--data-binary @"latest.yml" \
"$UPLOAD_URL?name=latest.yml&label=latest.yml"
fi
- name: Check Phaito.dmg
id: check_phaito_dmg
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ASSETS_URL: ${{ env.ASSETS_URL }}
run: |
assets=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "$ASSETS_URL")
PHATO_DMG_EXISTS=false
if echo "$assets" | jq -e '.[] | select(.name == "Phaito.dmg")'; then
PHATO_DMG_EXISTS=true
fi
echo "PHATO_DMG_EXISTS=$PHATO_DMG_EXISTS" >> $GITHUB_ENV
echo "PHATO_DMG_EXISTS : $PHATO_DMG_EXISTS"
- name: Check and duplicate Phaito.dmg
if: env.PHATO_DMG_EXISTS == 'false'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ASSETS_URL: ${{ env.ASSETS_URL }}
UPLOAD_URL: ${{ env.UPLOAD_URL }}
PHATO_DMG_EXISTS: ${{ env.PHATO_DMG_EXISTS }}
run: |
assets=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "$ASSETS_URL")
PHATO_DMG_EXISTS=false
if ! echo "$assets" | jq -e '.[] | select(.name == "Phaito.dmg")'; then
file_to_duplicate=$(echo "$assets" | jq -r '.[] | select(.name | test("^Phaito_.*\\.dmg$")) | .browser_download_url')
if [ -n "$file_to_duplicate" ]; then
# Download the file
curl -L -o Phaito.dmg "$file_to_duplicate"
# Upload the file
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary @"Phaito.dmg" \
"$UPLOAD_URL?name=Phaito.dmg&label=Phaito.dmg"
PHATO_DMG_EXISTS=true
fi
fi
echo "PHATO_DMG_EXISTS=$PHATO_DMG_EXISTS" >> $GITHUB_ENV
echo "PHATO_DMG_EXISTS : $PHATO_DMG_EXISTS"
- name: Check latest-mac.yml
id: check_latest_mac_yml
if: env.PHATO_DMG_EXISTS == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ASSETS_URL: ${{ env.ASSETS_URL }}
PHATO_DMG_EXISTS: ${{ env.PHATO_DMG_EXISTS }}
run: |
assets=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "$ASSETS_URL")
PHATO_LATEST_MAC_YML_EXISTS=false
if echo "$assets" | jq -e '.[] | select(.name == "latest-mac.yml")'; then
PHATO_LATEST_MAC_YML_EXISTS=true
fi
echo "PHATO_LATEST_MAC_YML_EXISTS=$PHATO_LATEST_MAC_YML_EXISTS" >> $GITHUB_ENV
echo "PHATO_DMG_EXISTS : ${{ env.PHATO_DMG_EXISTS }}"
echo "PHATO_LATEST_MAC_YML_EXISTS : $PHATO_LATEST_MAC_YML_EXISTS"
- name: Generate latest-mac.yml
if: env.PHATO_DMG_EXISTS == 'true' && env.PHATO_LATEST_MAC_YML_EXISTS == 'false'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ASSETS_URL: ${{ env.ASSETS_URL }}
VERSION: ${{ env.VERSION }}
PHATO_DMG_EXISTS: ${{ env.PHATO_DMG_EXISTS }}
PHATO_LATEST_MAC_YML_EXISTS: ${{ env.PHATO_LATEST_MAC_YML_EXISTS }}
run: |
assets=$(curl -s -H "Authorization: token $GITHUB_TOKEN" "$ASSETS_URL")
if ! echo "$assets" | jq -e '.[] | select(.name == "latest-mac.yml")'; then
file_to_duplicate_dmg=$(echo "$assets" | jq -r '.[] | select(.name | test("^Phaito_.*\\.dmg$")) | .browser_download_url')
if [ -n "$file_to_duplicate_dmg" ]; then
# Download the file
curl -L -o "Phaito_${VERSION}.dmg" "$file_to_duplicate_dmg"
fi
file_to_duplicate_zip=$(echo "$assets" | jq -r '.[] | select(.name | test("^Phaito_.*\\.zip$")) | .browser_download_url')
if [ -n "$file_to_duplicate_zip" ]; then
# Download the file
curl -L -o "Phaito_${VERSION}.zip" "$file_to_duplicate_zip"
fi
node scripts/generate-latest-yml.js "${VERSION}" "mac"
fi
- name: Upload latest-mac.yml
if: env.PHATO_DMG_EXISTS == 'true' && env.PHATO_LATEST_MAC_YML_EXISTS == 'false'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
UPLOAD_URL: ${{ env.UPLOAD_URL }}
PHATO_DMG_EXISTS: ${{ env.PHATO_DMG_EXISTS }}
PHATO_LATEST_MAC_YML_EXISTS: ${{ env.PHATO_LATEST_MAC_YML_EXISTS }}
run: |
if [ -f "latest-mac.yml" ]; then
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: text/yaml" \
--data-binary @"latest-mac.yml" \
"$UPLOAD_URL?name=latest-mac.yml&label=latest-mac.yml"
fi