This repository has been archived by the owner on May 24, 2024. It is now read-only.
Sample Bot #19
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: "Sample Bot" | |
on: | |
workflow_run: | |
workflows: [init banner] | |
types: | |
- completed | |
concurrency: | |
group: ${{ github.ref }} | |
cancel-in-progress: false | |
jobs: | |
checks: | |
runs-on: ubuntu-latest | |
steps: | |
- name: "ownership check" | |
env: | |
trig_actor: ${{ github.triggering_actor }} | |
repo_ownr: ${{ github.repository_owner }} | |
run: | | |
case "${trig_actor}" in | |
"${repo_ownr}"|github-actions*) : ;; | |
*) printf '%s\n'"Runner prevented to run because the script is executed by an untrusted user \"${trig_actor}\". (Only owner can execute, for security)" >&2 ; exit 1 ;; | |
esac | |
- name: "success checker" | |
run: | | |
if [ "${{ github.event.workflow_run.conclusion }}" != "success" ]; then | |
printf '%s\n' "Exiting... The init banner did not succeed..." >&2 | |
exit 1 | |
fi | |
- name: "check latest || (not implemented) dispatches if fails" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
LATEST_COMMIT="$(curl -s -H "Authorization: Bearer ${GITHUB_TOKEN}" "https://api.github.com/repos/${{ github.repository }}/commits/${{ github.ref }}" | jq -r .sha)" | |
if [ "${LATEST_COMMIT}" != "${GITHUB_SHA}" ]; then | |
printf '%s\n' "Current commit is not the latest." >&2 | |
# curl -H "Authorization: Bearer ${GITHUB_TOKEN}" -H "Accept: application/vnd.github.v3+json" -X POST -d '{"ref":"'"${{ github.ref }}"'","inputs":{}}' "https://api.github.com/repos/${{ github.repository }}/actions/workflows/process.yml/dispatches" | |
exit 1 | |
fi | |
- name: "check if repo checker have succeed" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
conclusion="$(curl -s -X GET "https://api.github.com/repos/${{ github.repository }}/actions/workflows/repo-checker.yml/runs" -H "Authorization: Bearer ${GITHUB_TOKEN}" | jq -r .workflow_runs[1].conclusion)" | |
if [[ "${conclusion}" = "failure" ]]; then | |
printf '%s\n' "failed due to repo checker failure." >&2 | |
curl -H "Authorization: Bearer ${GITHUB_TOKEN}" -H "Accept: application/vnd.github.v3+json" -X POST -d '{"ref":"'"${{ github.ref }}"'","inputs":{}}' "https://api.github.com/repos/${{ github.repository }}/actions/workflows/repo-checker.yml/dispatches" -o /dev/null | |
exit 1 | |
fi | |
sample-bot: | |
runs-on: ubuntu-latest | |
steps: | |
- name: "checkout" | |
uses: actions/checkout@v3 | |
- name: "run" | |
continue-on-error: true | |
env: | |
tok_fb: ${{ secrets.TOK_FB }} | |
tok_gif: ${{ secrets.TOK_GIF }} | |
run: bash frame_main.sh "${tok_fb}" "${tok_gif}" | |
- name: "commit changes" | |
uses: stefanzweifel/git-auto-commit-action@v4 | |
with: | |
commit_message: "stat: Posted!!" | |
repository: . | |
file_pattern: README.md fb/* main.sh counter*.txt frame_main.sh status/* scripts/* | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |