ioos / mbon-docs

MBON portal documentation
https://ioos.github.io/mbon-docs/
Other
0 stars 5 forks source link

Add gh-action for updating dropdown menus #30

Closed MathewBiddle closed 1 year ago

MathewBiddle commented 1 year ago

xref:

steps:
- name: Checkout repository
  uses: actions/checkout@v2
- name: Checkout submodules
  run: git submodule update --init --recursive

gh-action cron https://docs.getnacelle.com/deployment/scheduled-builds-github-actions.html#configure-the-schedule

MathewBiddle commented 1 year ago

also see this cron gh-action https://github.com/MathewBiddle/ioos_by_the_numbers/blob/main/.github/workflows/metrics.yml

MathewBiddle commented 1 year ago

image

Did it manually. Steps below:

  1. Updated the topnav_ioos.yml on the navbars branch.
  2. Committed those changes to the navbars branch (via PR and merge).
  3. Updated the submodule connections in the gh-pages branch here, using the git steps below.
> git submodule update --remote
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), 2.42 KiB | 248.00 KiB/s, done.
From https://github.com/ioos/documentation-theme-jekyll
   248d4c8..3a0e9ee  navbars    -> origin/navbars
Submodule path '_data/navbars_theme': checked out '3a0e9eecda1a82dd57e5a6cffba1f80411087141'
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), 2.42 KiB | 191.00 KiB/s, done.
From https://github.com/ioos/documentation-theme-jekyll
   248d4c8..3a0e9ee  navbars    -> origin/navbars

> git status
On branch gh-pages
Your branch is up to date with 'origin/gh-pages'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   _data/navbars_theme (new commits)

no changes added to commit (use "git add" and/or "git commit -a")

> git diff
diff --git a/_data/navbars_theme b/_data/navbars_theme
index 248d4c8..3a0e9ee 160000
--- a/_data/navbars_theme
+++ b/_data/navbars_theme
@@ -1 +1 @@
-Subproject commit 248d4c8ac0091d4f36b92ee39e45903e9fcd6d8e
+Subproject commit 3a0e9eecda1a82dd57e5a6cffba1f80411087141

> git commit -am "update theme" 
[gh-pages ae330ed] update theme
 1 file changed, 1 insertion(+), 1 deletion(-)

> git push origin gh-pages
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 328 bytes | 328.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
remote: 
remote: GitHub found 16 vulnerabilities on ioos/mbon-docs's default branch (10 high, 5 moderate, 1 low). To find out more, visit:
remote:      https://github.com/ioos/mbon-docs/security/dependabot
remote:
To https://github.com/ioos/mbon-docs.git
   ef7e22b..ae330ed  gh-pages -> gh-pages
MathewBiddle commented 1 year ago

@ocefpaf @mwengren mind taking a look at this gh-action?

https://github.com/ioos/mbon-docs/blob/gh-pages/.github/workflows/sync_theme.yml

The action is supposed to to the following tasks:

  1. Run every day at noon.
  2. Checkout the current repo gh-pages branch.
  3. Check for updates in the theme submodules
  4. Show the differences.
  5. Commit the changes.
  6. Push changes to gh-pages.

I am hopeful that we can simply copy this yml file to all of our ioos.github.io documentation sites and this will keep them up to date with our theme (if it changes).

MathewBiddle commented 1 year ago

seems to have worked: https://github.com/ioos/mbon-docs/actions/runs/4116540943/jobs/7106714685

In testing I changed the time so I could see the cron job run automatically.

ocefpaf commented 1 year ago

Cool, I had no idea we could do this with the checkout GHA.

Everything looks good to me. How are you following possible errors? Did you set GH to send you an email or are you watching the notifications?

PS: Do you know about crontab guru for cronjob checks? Screenshot from 2023-02-08 10-59-53

MathewBiddle commented 1 year ago

Thanks for the crontab guru reference! Super helpful.

How are you following possible errors?

Just watching the notifications for errors. Should probably do more error checking, but I wanted to get it working first.

The action ran successfully, but wasn't doing anything. Notice [1]. nothing to commit, working tree clean Essentially I am not pulling over the most recent version of each of the submodules.

Now, I'm trying to figure out how I pull over the most recent versions of the submodules. However, I'm running into an issue when git submodule update --remote because it can't find _data/navbars_theme. See [2].

According to [3], git pull --recurse-submodules might do the trick.

[1] - https://github.com/ioos/mbon-docs/actions/runs/4126722795/jobs/7129013459#step:3:13 [2] - https://github.com/ioos/mbon-docs/actions/runs/4135852464/jobs/7148885809#step:3:1 [3] - https://stackoverflow.com/questions/40987847/unable-to-find-current-origin-master-revision-in-submodule-path

mwengren commented 1 year ago

@MathewBiddle Based on what you discovered for the GHA config, was the git submodule update --init step the missing piece? Would that have resolved this issue: https://github.com/ioos/ioos-documentation-jekyll-skeleton/issues/4?

If so, we should probably update the HOWTO docs with that line: https://ioos.github.io/ioos-documentation-jekyll-skeleton/howto.html#a-note-on-submodules. I can look at that once I refresh my memory a bit.

MathewBiddle commented 1 year ago

Yes. After this commit the GHA worked correctly. https://github.com/ioos/mbon-docs/commit/d7520e5297cf7395e7eee9dfd2336a54bad6b277

You can see how it checked out the correct branch, then fast forwarded that branch to the most up to date (not sure if that was the update or the merge piece though): https://github.com/ioos/mbon-docs/actions/runs/4137189385/jobs/7152041754#step:3:1

I think I no longer need these lines, however. https://github.com/ioos/mbon-docs/blob/d8d1287b7c28617c149abd2e6e5c1d650d3d4205/.github/workflows/sync_theme.yml#L30-L34

Let me do some more tinkering to slim this GHA down.

MathewBiddle commented 1 year ago

Okay, so it's

git submodule update --init

This sets up the submodules with all the references defined in the .gitmodules file. But, it pulls over the last committed version that was used in this repo.

To update the submodules (once the references are established as above), run:

git submodule update --remote --merge

--remote tells git to update submodules without having to git pull for each of them.

One thing that helped me in deciphering where I was running into issues was using git submodule status and checking what branch was referenced (note remotes/origin/navbars - before this was pinned to a specific commit, eg 3a0e9ee). If it was pinned to a specific commit, the submodule wouldn't see any changes and thus nothing would happen.

+a2e22c750ad4056164fbf4ae6eeca2aa92173aa5 _data/navbars_theme (remotes/origin/navbars)
 6674af5f1b065d2d24e358472f428f864b023c60 theme (heads/master)

versus

3a0e9eecda1a82dd57e5a6cffba1f80411087141 _data/navbars_theme (3a0e9ee)
6674af5f1b065d2d24e358472f428f864b023c60 theme (heads/master)

The most recent GHA should be clear about what is happening https://github.com/ioos/mbon-docs/actions/runs/4177721923/workflow

mwengren commented 1 year ago

Yes, this all looks familiar now. The git submodule set-branch command shouldn't be needed and it reads instead from .gitmodules when --init is called.

So we need to keep the --merge flag as well? Earlier versions of your GHA didn't include it. So basically this should go in the HOWTO?

git submodule update --init
git submodule update --remote --merge

To pull in changes. With an optional

git submodule status

to confirm everything's working as it should?

MathewBiddle commented 1 year ago

correct.

MathewBiddle commented 1 year ago

done in https://github.com/ioos/mbon-docs/commit/e5a8dda4fa81190c384b6eaf36289f0cc2888286