Update .gitea/workflows/auto-release.yml
This commit is contained in:
@@ -8,105 +8,77 @@ on:
|
||||
jobs:
|
||||
update-and-release:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: python:3.12-slim
|
||||
|
||||
steps:
|
||||
- name: Install System Dependencies
|
||||
run: |
|
||||
apt-get update && apt-get install -y git
|
||||
|
||||
- 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: Install Python Dependencies
|
||||
run: pip install --no-cache-dir 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
|
||||
git config --global user.name "Gitea Actions"
|
||||
git config --global user.email "actions@gitea.local"
|
||||
# Safe directory is needed when running inside containers
|
||||
git config --global --add safe.directory '*'
|
||||
|
||||
- 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'
|
||||
id: git-check
|
||||
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
|
||||
echo "changes=true" >> $GITHUB_OUTPUT
|
||||
else
|
||||
echo "changes=false" >> $GITHUB_OUTPUT
|
||||
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'
|
||||
- name: Process Release
|
||||
if: steps.git-check.outputs.changes == 'true'
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.TOKEN }}
|
||||
GITEA_URL: ${{ secrets.GITEA_URL || github.server_url }}
|
||||
run: |
|
||||
# 1. Commit Changes
|
||||
git add discord-quest.js
|
||||
git commit -m "Update discord-quest.js from upstream gist"
|
||||
git push origin main
|
||||
|
||||
# 2. Calculate New Tag
|
||||
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
|
||||
VERSION=${LATEST_TAG#v}
|
||||
IFS='.' read -r major minor patch <<< "$VERSION"
|
||||
NEW_TAG="v$major.$minor.$((patch + 1))"
|
||||
|
||||
echo "Bumping version: $LATEST_TAG -> $NEW_TAG"
|
||||
|
||||
# 3. Push Tag
|
||||
git tag $NEW_TAG
|
||||
git push origin $NEW_TAG
|
||||
|
||||
# 4. Create Release via API
|
||||
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}" \
|
||||
curl -X POST "${GITEA_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/releases" \
|
||||
-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\",
|
||||
\"tag_name\": \"$NEW_TAG\",
|
||||
\"name\": \"Release $NEW_TAG\",
|
||||
\"body\": \"Automated release: Updated discord-quest.js\",
|
||||
\"draft\": false,
|
||||
\"prerelease\": false
|
||||
}"
|
||||
|
||||
}"
|
||||
Reference in New Issue
Block a user