Giter VIP home page Giter VIP logo

Comments (6)

brian-rose avatar brian-rose commented on May 29, 2024

#76 implements this but it doesn't work because the "delete preview" push to gh-pages gets cancelled before it does its thing.

from climatelaboratorybook.

brian-rose avatar brian-rose commented on May 29, 2024

Maybe the best approach is to set up a new action that runs after the rendered book is already pushed to gh-pages and simply checks out the gh-pages branch, deletes the appropriate _preview/[PR number] directory, and pushes the changes.

This action may be useful: https://github.com/marketplace/actions/add-commit

from climatelaboratorybook.

brian-rose avatar brian-rose commented on May 29, 2024

Or maybe a simpler one: https://github.com/stefanzweifel/git-auto-commit-action

from climatelaboratorybook.

brian-rose avatar brian-rose commented on May 29, 2024

Rather than running a delete action immediately upon merge, we could just run a daily or weekly "clean up" action that looks for anything in the _preview/ directory of the gh-pages branch, and removes anything not associated with a currently open PR.

For this, we would just need to be able to test if a given PR number is open.

from climatelaboratorybook.

brian-rose avatar brian-rose commented on May 29, 2024

Nevermind, I found a better / simpler solution.

In #77 We introduce a new delete_preview.yaml workflow that runs in the context

on:
  pull_request_target:
    types: closed

This means that it is called on merge OR on PR close, and either way it runs from the main branch so it has the credentials to push file changes to the gh_pages branch.

From there, it's just a matter of

  • checking out the gh_pages branch
  • deleting files in the appropriate _preview/[PR number] directory
  • pushing those changes to the GitHub repo

Then the gh-pages automation takes over.

If you watch the action reports, it looks like this action gets skipped when the main deploy-book.yaml action pushes to gh-pages. But that's just the part where GitHub takes the files in the gh-pages repo and deploys them to the pages website. The important thing is that we get the file changes pushed into the repo.

I tested this all out, and found that:

  • Previews are appropriately deleted when a PR is merged OR closed
  • This does NOT conflict with or accidentally delete other preview for still-open PRs

So basically all the functionality is there!

Some more candy could be added, like:

  • updating the message with the preview link to say that it's been deleted
  • not posting the link until the pages are actually visible on GitHub pages (I'm not sure how to do that)

But I don't think any of that is necessary right now.

from climatelaboratorybook.

brian-rose avatar brian-rose commented on May 29, 2024

I should finish migrating this repo to use the reusable Pythia Cookbook actions (following the Cookbook Template). Will leave this issue open until that work is done.

from climatelaboratorybook.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.