workflows/check-dead-repos: Use GITHUB_TOKEN when no credentials

Thanks goes to @Nable80 for shedding a light on the matter:

https://github.com/oh-my-fish/packages-main/commit/50c23f5869f6611d65fed65896aeef01bc9ed37c#commitcomment-77590391
parent 18ad7980
...@@ -12,9 +12,7 @@ ...@@ -12,9 +12,7 @@
function read_repository -a user_repo function read_repository -a user_repo
set -l url https://api.github.com/repos/$user_repo set -l url https://api.github.com/repos/$user_repo
test "$USERNAME:$TOKEN" != ":" curl -s -H "Authorization: Bearer $GITHUB_TOKEN" $url
and curl -s -u $USERNAME:$TOKEN $url
or curl -s $url
end end
set -l packages packages/* set -l packages packages/*
......
name: Check for dead repositories name: Check for dead repositories
on: on:
push: push:
pull_request:
schedule: schedule:
- cron: '30 5,17 * * *' - cron: '30 5,17 * * *'
workflow_run:
workflows: [Pull Request Artifacts]
types:
- completed
jobs: jobs:
check-dead-repos: check-dead-repos:
runs-on: ubuntu-latest runs-on: ubuntu-latest
env: env:
USERNAME: ${{ secrets.USERNAME }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TOKEN: ${{ secrets.TOKEN }}
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
with: with:
set-safe-directory: false set-safe-directory: false
- name: Install dependencies - name: Install dependencies
run: sudo apt update && sudo apt install -y fish python3 run: sudo apt update && sudo apt install -y fish python3
- name: Download artifact
if: >
(github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success')
uses: actions/github-script@v6.1.0
with:
script: |
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "packages"
})[0];
var download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{ github.workspace }}/packages.zip', Buffer.from(download.data));
- name: Unzip packages
if: >
(github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success')
run: |
rm packages/*
unzip packages.zip
- name: Check dead repositories - name: Check dead repositories
id: check id: check
run: fish .github/workflows/check-dead-repos.fish run: fish .github/workflows/check-dead-repos.fish
- name: Comment success on PR
if: ${{ always() && (github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success') }}
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
var fs = require('fs');
var issue_number = Number(fs.readFileSync('.pr_number'));
await github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: '${{ steps.check.conclusion }}' == 'success' ?
'✅ Everything looks OK! [Workflow ran successfully](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}).' :
'🔴 Check for dead repositories failed! [Workflow failed](https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}).'
});
name: Pull Request Artifacts
on:
pull_request:
jobs:
pull-request-artifacts:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Save PR number
run: |
echo "${{ github.event.number }}" > .pr_number
- name: Upload artifact
uses: actions/upload-artifact@v2
with:
name: packages
path: |
packages/
.pr_number
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment