113 lines
3.5 KiB
YAML
113 lines
3.5 KiB
YAML
name: Auto Release
|
|
|
|
on:
|
|
schedule:
|
|
- cron: '0 0 * * *'
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
update-and-release:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Set up Python
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version: '3.x'
|
|
|
|
- name: Install dependencies
|
|
run: pip install requests
|
|
|
|
- name: Configure Git
|
|
run: |
|
|
git config user.name "Gitea Actions"
|
|
git config user.email "actions@gitea.local"
|
|
|
|
- name: Get file hash before update
|
|
id: before
|
|
run: |
|
|
if [ -f discord-quest.js ]; then
|
|
echo "hash=$(sha256sum discord-quest.js | cut -d' ' -f1)" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "hash=" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Run update script
|
|
id: update
|
|
env:
|
|
GITEA_ACTIONS: true
|
|
run: python main.py || true
|
|
|
|
- name: Get file hash after update
|
|
id: after
|
|
run: |
|
|
if [ -f discord-quest.js ]; then
|
|
echo "hash=$(sha256sum discord-quest.js | cut -d' ' -f1)" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "hash=" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Check for changes
|
|
id: changes
|
|
run: |
|
|
if [ "${{ steps.before.outputs.hash }}" != "${{ steps.after.outputs.hash }}" ]; then
|
|
echo "changed=true" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "changed=false" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Commit and push changes
|
|
if: steps.changes.outputs.changed == 'true'
|
|
run: |
|
|
if [ -n "$(git status --porcelain discord-quest.js)" ]; then
|
|
git add discord-quest.js
|
|
git commit -m "Update discord-quest.js from upstream gist"
|
|
git push origin main
|
|
fi
|
|
|
|
- name: Get latest tag
|
|
if: steps.changes.outputs.changed == 'true'
|
|
id: tag
|
|
run: |
|
|
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
|
|
echo "latest=$latest_tag" >> $GITHUB_OUTPUT
|
|
|
|
version=$(echo $latest_tag | sed 's/v//')
|
|
IFS='.' read -r major minor patch <<< "$version"
|
|
patch=$((patch + 1))
|
|
new_tag="v${major}.${minor}.${patch}"
|
|
echo "new=$new_tag" >> $GITHUB_OUTPUT
|
|
|
|
- name: Create and push tag
|
|
if: steps.changes.outputs.changed == 'true'
|
|
run: |
|
|
git tag ${{ steps.tag.outputs.new }}
|
|
git push origin ${{ steps.tag.outputs.new }}
|
|
|
|
- name: Create Gitea release
|
|
if: steps.changes.outputs.changed == 'true'
|
|
env:
|
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
|
GITEA_URL: ${{ secrets.GITEA_URL || github.server_url }}
|
|
run: |
|
|
REPO_OWNER=$(echo ${{ github.repository }} | cut -d'/' -f1)
|
|
REPO_NAME=$(echo ${{ github.repository }} | cut -d'/' -f2)
|
|
|
|
API_URL="${GITEA_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/releases"
|
|
|
|
curl -X POST "${API_URL}" \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{
|
|
\"tag_name\": \"${{ steps.tag.outputs.new }}\",
|
|
\"name\": \"Release ${{ steps.tag.outputs.new }}\",
|
|
\"body\": \"Automated release: Updated discord-quest.js from upstream gist\",
|
|
\"draft\": false,
|
|
\"prerelease\": false
|
|
}"
|
|
|