Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update workflows to be fully re-useable #10

Merged
merged 41 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
2aee992
first step of the no token workflow: make things optional
zkamvar Dec 19, 2024
0a24641
add fallback for token maker
zkamvar Dec 19, 2024
548ca2b
try another approach
zkamvar Dec 19, 2024
8a39596
try another approach
zkamvar Dec 19, 2024
897e08a
try to use github token
zkamvar Dec 19, 2024
49e683f
huh
zkamvar Dec 19, 2024
9da72fc
dangit
zkamvar Dec 19, 2024
5efb09a
d'oh
zkamvar Dec 19, 2024
18966db
make things more explicit
zkamvar Dec 19, 2024
3640c20
ya
zkamvar Dec 19, 2024
a9fe957
wth
zkamvar Dec 19, 2024
bd0d0f6
switch to key
zkamvar Dec 19, 2024
2960858
key
zkamvar Dec 19, 2024
d185a65
auto-add bot tag to slug if bot
zkamvar Dec 19, 2024
0b2dc1d
fix secret name
zkamvar Dec 19, 2024
f2d7e1d
adapt generate-data to same workflow
zkamvar Dec 19, 2024
797ea7a
fix assumptions for branch creator
zkamvar Dec 19, 2024
0603267
checkout scripts for data generator
zkamvar Dec 19, 2024
76fc694
rearrange
zkamvar Dec 19, 2024
59ab0fa
set scripts path
zkamvar Dec 19, 2024
b46fb7a
checkout into temp dir
zkamvar Dec 19, 2024
290b27d
fix location of tempdir
zkamvar Dec 19, 2024
55b06fd
one last time
zkamvar Dec 19, 2024
4ce6fa9
fuck this
zkamvar Dec 19, 2024
dffe0ec
test app-workflow
zkamvar Dec 20, 2024
4511e9c
dangit BASH
zkamvar Dec 20, 2024
a9b617e
dangit
zkamvar Dec 20, 2024
0ba8ce9
no truth
zkamvar Dec 20, 2024
8bc80b2
fix bot bug
zkamvar Dec 20, 2024
f606ed0
only clone if the branch is so fetch
zkamvar Dec 20, 2024
5a7093e
i hate this
zkamvar Dec 20, 2024
7073094
force GitHub to understand wth this means
zkamvar Dec 20, 2024
6889842
Revert "force GitHub to understand wth this means"
zkamvar Dec 20, 2024
c7ce2f3
from json to hell
zkamvar Dec 20, 2024
db4f0bb
fromJSON is the correct pattern
zkamvar Dec 20, 2024
9f28b48
:see_no_evil:
zkamvar Dec 20, 2024
d65c750
set test for data
zkamvar Dec 20, 2024
7d4bfa0
fix regenerate key
zkamvar Dec 20, 2024
87ebca5
use fromJSON for boolean
zkamvar Dec 20, 2024
c4f8af2
fall back to false
zkamvar Dec 20, 2024
6950655
Apply suggestions from code review
zkamvar Dec 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 42 additions & 7 deletions .github/workflows/generate-data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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 }}
Expand All @@ -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: |
Expand All @@ -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'
Expand Down Expand Up @@ -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:
Expand All @@ -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 }}
Expand All @@ -173,15 +208,15 @@ 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:
persist-credentials: false
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:
Expand All @@ -195,4 +230,4 @@ jobs:
"${{ steps.id.outputs.repo }}" \
"${{ inputs.slug }}" \
"${{ inputs.email }}" \
"${{ steps.token.outputs.token }}"
"${{ steps.token.outputs.token || secrets.key }}"
37 changes: 30 additions & 7 deletions .github/workflows/generate-site.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -81,15 +93,15 @@ 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:
name: ${{ steps.id.outputs.file }}
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:
Expand Down Expand Up @@ -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 }}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -162,4 +185,4 @@ jobs:
"${{ steps.id.outputs.repo }}" \
"${{ inputs.slug }}" \
"${{ inputs.email }}" \
"${{ steps.token.outputs.token }}"
"${{ steps.token.outputs.token || secrets.key }}"
6 changes: 3 additions & 3 deletions .github/workflows/rebuild-data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ on:

jobs:
repos:
uses: hubverse-org/hub-dashboard-control-room/.github/workflows/get-installations.yaml@main
uses: hubverse-org/hub-dashboard-control-room/.github/workflows/get-installations.yaml@znk/no-token
zkamvar marked this conversation as resolved.
Show resolved Hide resolved
with:
newbies: '${{ toJSON(github.event.client_payload.newbies) }}'
secrets:
id: ${{ vars.APP_ID }}
key: ${{ secrets.PRIVATE_KEY }}
site:
needs: [repos]
uses: hubverse-org/hub-dashboard-control-room/.github/workflows/generate-data.yaml@main
uses: hubverse-org/hub-dashboard-control-room/.github/workflows/generate-data.yaml@znk/no-token
zkamvar marked this conversation as resolved.
Show resolved Hide resolved
with:
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 }}
zkamvar marked this conversation as resolved.
Show resolved Hide resolved
secrets:
id: ${{ vars.APP_ID }}
key: ${{ secrets.PRIVATE_KEY }}
4 changes: 2 additions & 2 deletions .github/workflows/rebuild-site.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ on:

jobs:
repos:
uses: hubverse-org/hub-dashboard-control-room/.github/workflows/get-installations.yaml@main
uses: hubverse-org/hub-dashboard-control-room/.github/workflows/get-installations.yaml@znk/no-token
zkamvar marked this conversation as resolved.
Show resolved Hide resolved
with:
newbies: '${{ toJSON(github.event.client_payload.newbies) }}'
secrets:
id: ${{ vars.APP_ID }}
key: ${{ secrets.PRIVATE_KEY }}
site:
needs: [repos]
uses: hubverse-org/hub-dashboard-control-room/.github/workflows/generate-site.yaml@main
uses: hubverse-org/hub-dashboard-control-room/.github/workflows/generate-site.yaml@znk/no-token
zkamvar marked this conversation as resolved.
Show resolved Hide resolved
with:
repos: '${{ needs.repos.outputs.repos }}'
slug: '${{ needs.repos.outputs.slug }}'
Expand Down
2 changes: 1 addition & 1 deletion appHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions scripts/check-branch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions scripts/pushit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading