Auto‑generate YOURLS patch #67
This file contains hidden or 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: Auto‑generate YOURLS patch | |
on: | |
schedule: | |
- cron: '0 0 * * *' | |
workflow_dispatch: | |
jobs: | |
check: | |
name: Check for new YOURLS release | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
outputs: | |
old: ${{ steps.check.outputs.old }} | |
new: ${{ steps.check.outputs.new }} | |
proceed: ${{ steps.check.outputs.proceed }} | |
steps: | |
- name: Determine upstream tags & whether to proceed | |
id: check | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const ups = await github.rest.repos.listReleases({ | |
owner: 'YOURLS', | |
repo: 'YOURLS', | |
per_page: 2 | |
}); | |
if (ups.data.length < 2) { | |
throw new Error("Upstream YOURLS has fewer than 2 releases"); | |
} | |
const newTag = ups.data[0].tag_name; | |
const oldTag = ups.data[1].tag_name; | |
let exists = true; | |
try { | |
await github.rest.repos.getReleaseByTag({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
tag: newTag | |
}); | |
} catch (e) { | |
if (e.status === 404) exists = false; | |
} | |
core.setOutput('new', newTag); | |
core.setOutput('old', oldTag); | |
core.setOutput('proceed', exists ? 'false' : 'true'); | |
create_patch: | |
name: Generate & publish patch | |
needs: check | |
permissions: | |
contents: write | |
if: needs.check.outputs.proceed == 'true' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: '3.x' | |
- name: Install dependencies | |
run: | | |
pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: Generate patch and manifest | |
run: | | |
OLD=${{ needs.check.outputs.old }} | |
NEW=${{ needs.check.outputs.new }} | |
python YOURLS-diff_CreatePackage.py --old "$OLD" --new "$NEW" --summary | |
env: | |
PYTHONUNBUFFERED: '1' | |
- name: Determine which artifacts to upload | |
id: build_artifacts | |
run: | | |
OLD=${{ needs.check.outputs.old }} | |
NEW=${{ needs.check.outputs.new }} | |
ARTIFACTS="YOURLS-update-$OLD-to-$NEW.zip YOURLS-update-$OLD-to-$NEW.txt" | |
if [ -f "YOURLS-update-$OLD-to-$NEW.removed.txt" ]; then | |
ARTIFACTS="$ARTIFACTS YOURLS-update-$OLD-to-$NEW.removed.txt" | |
fi | |
echo "artifact_files=$ARTIFACTS" >> $GITHUB_OUTPUT | |
- name: Create Release & Upload Patch | |
uses: ncipollo/release-action@v1 | |
with: | |
tag: ${{ needs.check.outputs.new }} | |
name: "${{ needs.check.outputs.old }} to ${{ needs.check.outputs.new }}" | |
bodyFile: YOURLS-update-${{ needs.check.outputs.old }}-to-${{ needs.check.outputs.new }}.summary.txt | |
draft: false | |
prerelease: false | |
artifacts: ${{ steps.build_artifacts.outputs.artifact_files }} | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |