update-checker #1
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
name: update-checker | |
on: | |
workflow_dispatch: | |
env: | |
status: failure | |
workflow_name: none | |
apk-path: none | |
repo-title: none | |
jobs: | |
check_for_update: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Run Main.go | |
id: run-main | |
run: | | |
go run ./src/main.go --token="${{ secrets.GITHUB_TOKEN }}" | |
- name: Set Environment Variables | |
run: | | |
echo "status=$(jq -r '.status' data/info.json)" >> $GITHUB_ENV | |
echo "workflow_name=$(jq -r '.workflow.title' data/info.json)" >> $GITHUB_ENV | |
echo "repo-title=$(jq -r '.workflow.repo' data/settings.json)" >> $GITHUB_ENV | |
echo "apk-path=$(ls -S archive/*.apk | head -n 1)" >> $GITHUB_ENV | |
- name: Make Commit Log | |
run: | | |
echo "$(jq -r '.["commit-log"]' data/info.json)" > ./data/commit-log.txt | |
- name: Get Apk Info | |
id: apk-info | |
if: ${{ env.status == 'success' }} | |
uses: hkusu/apk-info-action@v1 | |
with: | |
apk-path: ${{ env.apk-path }} | |
- name: Commit Changes | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "${{ github.repository_owner }}" | |
git add . | |
git commit -m "Update ${{ env.repo-title }} to latest version" | |
- name: Push Changes | |
uses: ad-m/github-push-action@master | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Delete Old Releases | |
run: | | |
releases=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/${{ github.repository }}/releases | jq -r '.[] | .id' | sort -nr) | |
for release in $releases; do | |
curl -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/${{ github.repository }}/releases/$release | |
done | |
if: ${{ env.status == 'success' }} | |
- name: Delete Old Tags | |
run: | | |
tags=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/${{ github.repository }}/tags | jq -r '.[] | .name') | |
for tag in $tags; do | |
curl -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/${{ github.repository }}/git/refs/tags/$tag | |
done | |
if: ${{ env.status == 'success' }} | |
- name: Publish Release | |
uses: softprops/action-gh-release@v2 | |
if: ${{ env.status == 'success' }} | |
with: | |
files: ./archive/*.apk | |
tag_name: ${{ steps.apk-info.outputs.version-name }} | |
name: ${{ env.workflow_name }} | |
body_path: ./data/commit-log.txt | |
rerun-workflow: | |
name: Re-run workflow | |
needs: check_for_update | |
if: success() || failure() | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
- name: Wait for 5 minutes | |
run: | | |
elapsed_time=$(jq -r '.["elapsed-time"]' data/info.json) | |
if [ $elapsed_time -lt 300 ]; then | |
sleep $((300 - elapsed_time)) | |
fi | |
- name: Re-trigger workflow | |
run: gh workflow run checker.yaml | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
GH_REPO: ${{ github.repository }} |