Skip to content

Auto-generate YOURLS patch #137

Auto-generate YOURLS patch

Auto-generate YOURLS patch #137

Workflow file for this run

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@v5
- 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: Debug final file list
run: ls -l
- name: Determine which artifacts to upload
id: build_artifacts
run: |
OLD=${{ needs.check.outputs.old }}
NEW=${{ needs.check.outputs.new }}
FILES="YOURLS-update-$OLD-to-$NEW.zip,YOURLS-update-$OLD-to-$NEW.txt"
if [ -f "YOURLS-update-$OLD-to-$NEW.summary.txt" ]; then
FILES="$FILES,YOURLS-update-$OLD-to-$NEW.summary.txt"
fi
if [ -f "YOURLS-update-$OLD-to-$NEW.removed.txt" ]; then
FILES="$FILES,YOURLS-update-$OLD-to-$NEW.removed.txt"
else
echo "No removed file list generated: no files were removed between $OLD and $NEW."
fi
if [ -f "YOURLS-deploy-$OLD-to-$NEW.sh" ]; then
FILES="$FILES,YOURLS-deploy-$OLD-to-$NEW.sh"
fi
echo "artifact_files=$FILES" >> "$GITHUB_OUTPUT"
echo "Artifact files list prepared: $FILES"
- name: Check artifact files exist
run: |
IFS=',' read -ra files <<< "${{ steps.build_artifacts.outputs.artifact_files }}"
for f in "${files[@]}"; do
if [ ! -f "$f" ]; then
echo "File missing: $f"
exit 1
fi
done
- 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 }}