Check for updates #1940
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: Check for updates | |
on: | |
push: | |
branches: [ main ] | |
paths: [ .github/workflows/stable-check.yml, scripts/**, crates/**, stable.template.yml ] | |
pull_request: | |
branches: [ main ] | |
paths: [ .github/workflows/stable-check.yml, scripts/**, crates/**, stable.template.yml, pr/_allowlist ] | |
workflow_dispatch: | |
schedule: | |
- cron: '0 6 * * *' | |
permissions: | |
contents: write | |
env: | |
python-version: "3.12" | |
jobs: | |
check: | |
outputs: | |
crates: ${{ steps.check.outputs.crates }} | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ env.python-version }} | |
- name: Skip Duplicate Actions | |
if: ${{ github.event_name != 'pull_request' }} | |
uses: fkirc/skip-duplicate-actions@v5 | |
id: skip | |
with: | |
skip_after_successful_duplicate: false | |
do_not_skip: '["pull_request"]' | |
concurrent_skipping: always | |
- name: Check for updates | |
id: check | |
run: echo "crates=$(python ./scripts/check.py '${{ github.event_name == 'pull_request' }}' '${{ steps.skip.outputs.should_skip }}' '${{ github.server_url }}' '${{ github.repository }}')" >> $GITHUB_OUTPUT | |
dispatch: | |
if: ${{ needs.check.outputs.crates != '{}' }} | |
strategy: | |
max-parallel: 1 | |
matrix: ${{ fromJson(needs.check.outputs.crates) }} | |
runs-on: ubuntu-latest | |
needs: [ check ] | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ env.python-version }} | |
- name: Generate workflow | |
run: python ./scripts/gen.py ${{ github.event_name == 'pull_request' }} '${{ github.server_url }}/${{ github.repository }}' '${{ matrix.crate }}' '${{ matrix.version }}' '${{ matrix.dl }}' '${{ matrix.checksum }}' '${{ matrix.file }}' | |
- name: Print generated workflow file | |
run: cat .github/workflows/stable-${{ matrix.crate }}.yml | |
- name: Wait | |
if: ${{ github.event_name != 'pull_request' }} | |
run: sleep 15m | |
- name: Run Generated Workflow | |
env: | |
GITHUB_TOKEN: ${{ secrets.WORKFLOW_TOKEN }} | |
run: | | |
set -euxo pipefail | |
TEMP_DIR="$(mktemp -d)" | |
# Move files | |
mkdir -p "$TEMP_DIR/crates" | |
cp '${{ matrix.file }}' "$TEMP_DIR/crates" | |
mkdir -p "$TEMP_DIR/.github/workflows" | |
cp '.github/workflows/stable-${{ matrix.crate }}.yml' "$TEMP_DIR/.github/workflows" | |
cp -r 'keys' 'scripts' $TEMP_DIR | |
rm -rf $TEMP_DIR/scripts/__pycache__ | |
# Commit and Push | |
pushd $TEMP_DIR | |
git init | |
git config user.name 'github-actions' | |
git config user.email 'github-actions@noreply.github.com' | |
git remote add origin "https://${{ github.actor }}:$GITHUB_TOKEN@github.com/${{ github.repository }}.git" | |
git checkout -b tmp | |
git add -f . | |
git commit -m "Publish crate ${{ matrix.crate }} ${{ matrix.version }} from #${{ github.run_number }}" | |
git push --force origin tmp:trigger/stable | |
# Cleanup | |
popd | |
rm -rf $TEMP_DIR | |
wait: | |
if: ${{ github.event_name != 'pull_request' }} | |
runs-on: ubuntu-latest | |
needs: [ dispatch ] | |
steps: | |
- uses: actions/checkout@v4 | |
- run: sleep 15m | |
archive: | |
if: ${{ github.event_name != 'pull_request' }} | |
strategy: | |
max-parallel: 1 | |
matrix: | |
type: [ stable ] | |
runs-on: ubuntu-latest | |
needs: [ wait ] | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: archive | |
persist-credentials: false | |
fetch-depth: 0 | |
- name: Clean | |
working-directory: ./${{ matrix.type }} | |
run: rm -rf * | |
- name: Archive | |
uses: robinraju/release-downloader@v1.9 | |
with: | |
tag: "${{ matrix.type }}-index" | |
fileName: "*" | |
out-file-path: "./${{ matrix.type }}" | |
- name: Commit and Push | |
shell: bash | |
run: | | |
set -euxo pipefail | |
git config --local user.name 'github-actions[bot]' | |
git config --local user.email 'github-actions[bot]@users.noreply.github.com' | |
git commit -a --allow-empty -m "chore: autopublish $(date --utc)" | |
git push "https://${GITHUB_ACTOR}:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git" HEAD:archive --follow-tags |