diff --git a/.github/workflows/generate-data.yaml b/.github/workflows/generate-data.yaml index 1429684..10dc0dc 100644 --- a/.github/workflows/generate-data.yaml +++ b/.github/workflows/generate-data.yaml @@ -26,10 +26,20 @@ jobs: name: "Generate Data" runs-on: ubuntu-latest continue-on-error: true - strategy: - matrix: + strategy: + matrix: site: ${{ fromJSON(inputs.repos) }} steps: + - id: is-bot + name: "Check if we are running a bot" + run: | + if [[ "${{ secrets.id }}" = "none" ]]; then + bot=false + else + bot=true + fi + echo "bot=$bot" >> "$GITHUB_OUTPUT" + shell: bash - id: id name: "setup run variables" run: | @@ -52,6 +62,7 @@ jobs: pip install --upgrade pip pip install git+https://github.com/hubverse-org/hub-dashboard-predtimechart - uses: actions/create-github-app-token@v1 + if: ${{ fromJSON(steps.is-bot.outputs.bot) }} id: token with: app-id: ${{ secrets.id }} @@ -63,7 +74,7 @@ jobs: uses: actions/checkout@v4 with: persist-credentials: false - token: ${{ steps.token.outputs.token }} + token: ${{ steps.token.outputs.token || secrets.key }} repository: ${{ steps.id.outputs.repo }} sparse-checkout-cone-mode: false sparse-checkout: | @@ -77,11 +88,24 @@ jobs: echo "::error title=Missing config (${{ steps.id.outputs.repo }})::No predtimechart-config.yml file found. Exiting." exit 1 fi + - id: check-branch + name: "check for ptc/data branch" + env: + GH_TOKEN: ${{ steps.token.outputs.token || secrets.key }} + run: | + exists=$(gh api -X GET "repos/${{ steps.id.outputs.repo }}/branches" --jq '.[].name | select(. == "ptc/data")') + if [[ "$exists" = "ptc/data" ]]; then + fetch=true + else + fetch=false + fi + echo "fetch=$fetch" >> "$GITHUB_OUTPUT" - id: checkout-data + if: ${{ fromJSON(steps.check-branch.outputs.fetch) }} name: "Checkout ptc/data branch" uses: actions/checkout@v4 with: - token: ${{ steps.token.outputs.token }} + token: ${{ steps.token.outputs.token || secrets.key }} persist-credentials: false repository: ${{ steps.id.outputs.repo }} ref: 'ptc/data' @@ -142,6 +166,16 @@ jobs: matrix: site: ${{ fromJSON(inputs.repos) }} steps: + - id: is-bot + name: "Check if we are running a bot" + run: | + if [[ "${{ secrets.id }}" = "none" ]]; then + bot=false + else + bot=true + fi + echo "bot=$bot" >> "$GITHUB_OUTPUT" + shell: bash - id: checkout-this-here-repo-scripts uses: actions/checkout@v4 with: @@ -157,6 +191,7 @@ jobs: echo "repo=$owner/$name" >> $GITHUB_OUTPUT echo "file=$owner-$name-data" >> $GITHUB_OUTPUT - uses: actions/create-github-app-token@v1 + if: ${{ fromJSON(steps.is-bot.outputs.bot) }} id: token with: app-id: ${{ secrets.id }} @@ -173,7 +208,7 @@ jobs: "${{ steps.id.outputs.repo }}" \ "${{ inputs.slug }}" \ "${{ inputs.email }}" \ - "${{ steps.token.outputs.token }}" + "${{ steps.token.outputs.token || secrets.key }}" - id: checkout-pages uses: actions/checkout@v4 with: @@ -181,7 +216,7 @@ jobs: repository: ${{ steps.id.outputs.repo }} ref: ptc/data path: 'data' - token: ${{ steps.token.outputs.token }} + token: ${{ steps.token.outputs.token || secrets.key }} - id: fetch-artifact uses: actions/download-artifact@v4 with: @@ -195,4 +230,4 @@ jobs: "${{ steps.id.outputs.repo }}" \ "${{ inputs.slug }}" \ "${{ inputs.email }}" \ - "${{ steps.token.outputs.token }}" + "${{ steps.token.outputs.token || secrets.key }}" diff --git a/.github/workflows/generate-site.yaml b/.github/workflows/generate-site.yaml index 463b583..7689bc9 100644 --- a/.github/workflows/generate-site.yaml +++ b/.github/workflows/generate-site.yaml @@ -34,7 +34,19 @@ jobs: volumes: - ${{ github.workspace }}:/site steps: + - id: is-bot + name: "Check if we are running a bot" + run: | + if [[ "${{ secrets.id }}" = "none" ]]; then + bot=false + else + bot=true + fi + echo "bot is $bot" + echo "bot=$bot" >> "$GITHUB_OUTPUT" + shell: bash - uses: actions/create-github-app-token@v1 + if: ${{ fromJSON(steps.is-bot.outputs.bot) }} name: "Generate App Token (if no token present)" id: token with: @@ -53,7 +65,7 @@ jobs: name: "Fetch ${{ steps.id.outputs.repo }}" uses: actions/checkout@v4 with: - token: ${{ steps.token.outputs.token }} + token: ${{ steps.token.outputs.token || secrets.key }} persist-credentials: false repository: ${{ steps.id.outputs.repo }} - id: check-configs @@ -81,7 +93,7 @@ jobs: && echo "success=true" >> $GITHUB_OUTPUT \ || echo "success=false" >> $GITHUB_OUTPUT - name: Upload artifact - # if: ${{ steps.build-site.outputs.success == true }} + # if: ${{ fromJSON(steps.build-site.outputs.success) }} id: upload uses: actions/upload-artifact@v4 with: @@ -89,7 +101,7 @@ jobs: path: '/site/pages/' retention-days: 1 # - name: signal success - # # if: ${{ steps.build-site.outputs.success == true }} + # # if: ${{ fromJSON(steps.build-site.outputs.success) }} # run: | # touch "${{runner.temp}}/${{steps.id.outputs.file}}.success" push-site: @@ -122,7 +134,18 @@ jobs: persist-credentials: false sparse-checkout: | scripts + - id: is-bot + name: "Check if we are running a bot" + run: | + if [[ "${{ secrets.id }}" = "none" ]]; then + bot=false + else + bot=true + fi + echo "bot=$bot" >> "$GITHUB_OUTPUT" + shell: bash - uses: actions/create-github-app-token@v1 + if: ${{ fromJSON(steps.is-bot.outputs.bot) }} id: token with: app-id: ${{ secrets.id }} @@ -132,14 +155,14 @@ jobs: - id: check-branch name: "check for gh-pages branch and create if needed" env: - GH_TOKEN: ${{ github.token }} + GH_TOKEN: ${{ steps.token.outputs.token || secrets.key }} run: | bash -x "${{ github.workspace }}/scripts/check-branch.sh" \ "gh-pages" \ "${{ steps.id.outputs.repo }}" \ "${{ inputs.slug }}" \ "${{ inputs.email }}" \ - "${{ steps.token.outputs.token }}" + "${{ steps.token.outputs.token || secrets.key }}" - id: checkout-pages name: "Fetch ${{ steps.id.outputs.repo }}" uses: actions/checkout@v4 @@ -148,7 +171,7 @@ jobs: repository: ${{ steps.id.outputs.repo }} ref: gh-pages path: 'pages' - token: ${{ steps.token.outputs.token }} + token: ${{ steps.token.outputs.token || secrets.key }} - id: fetch-artifact name: "Load changes" uses: actions/download-artifact@v4 @@ -162,4 +185,4 @@ jobs: "${{ steps.id.outputs.repo }}" \ "${{ inputs.slug }}" \ "${{ inputs.email }}" \ - "${{ steps.token.outputs.token }}" + "${{ steps.token.outputs.token || secrets.key }}" diff --git a/.github/workflows/rebuild-data.yaml b/.github/workflows/rebuild-data.yaml index 3d57f80..9368955 100644 --- a/.github/workflows/rebuild-data.yaml +++ b/.github/workflows/rebuild-data.yaml @@ -22,7 +22,7 @@ jobs: repos: '${{ needs.repos.outputs.repos }}' slug: '${{ needs.repos.outputs.slug }}' email: '${{ needs.repos.outputs.email }}' - regenerate: ${{ github.event.client_payload.regenerate }} + regenerate: ${{ github.event.client_payload.regenerate || false }} secrets: id: ${{ vars.APP_ID }} key: ${{ secrets.PRIVATE_KEY }} diff --git a/appHelper.py b/appHelper.py index 52367c3..ce66b30 100644 --- a/appHelper.py +++ b/appHelper.py @@ -61,7 +61,7 @@ def get_slug_id(): app = ghapp["app"] app_usr = gh.get_user(app.slug+"[bot]") email = f'{app_usr.id}+{app_usr.login}@users.noreply.github.com' - write_string("slug", app.slug) + write_string("slug", app.slug + "[bot]") write_string("email", email) write_string("id", app_usr.id) diff --git a/scripts/check-branch.sh b/scripts/check-branch.sh index 11236f1..cdaf881 100644 --- a/scripts/check-branch.sh +++ b/scripts/check-branch.sh @@ -11,12 +11,12 @@ exists=$(gh api -X GET "repos/${repo}/branches" --jq '.[].name | select(. == "${ if [[ "$exists" != "${branch}" ]]; then tmp=$(mktemp --directory) cd "$tmp" - git config --global user.name "${slug}[bot]" + git config --global user.name "${slug}" git config --global user.email "${email}" git init git switch -c "${branch}" - git remote add origin https://${slug}[bot]:${token}@github.com/${repo}.git - git commit --allow-empty -m 'initial ${branch} commit' + git remote add origin https://${slug}:${token}@github.com/${repo}.git + git commit --allow-empty -m "initial ${branch} commit" git push --set-upstream origin "${branch}" cd fi diff --git a/scripts/pushit.sh b/scripts/pushit.sh index 23bcce9..c6f9cd2 100644 --- a/scripts/pushit.sh +++ b/scripts/pushit.sh @@ -17,9 +17,9 @@ else fi cd "$dir" || (echo "Directory '$dir' not found" && exit 1) -git config --global user.name "${slug}[bot]" +git config --global user.name "${slug}" git config --global user.email "${email}" -git remote set-url origin "https://${slug}[bot]:${token}@github.com/${repo}.git" +git remote set-url origin "https://${slug}:${token}@github.com/${repo}.git" ls git status if [[ "${amend}" == "true" ]]; then