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

Support running a custom script before adding and committing #331

Closed
Xiphe opened this issue Jan 29, 2020 · 12 comments
Closed

Support running a custom script before adding and committing #331

Xiphe opened this issue Jan 29, 2020 · 12 comments

Comments

@Xiphe
Copy link
Contributor

Xiphe commented Jan 29, 2020

I would really like to execute manual cleanup after new files have been copied but before everything is added.

Ideally I could just hook in a function that receives the git instance.

API proposal

lib

var ghpages = require('gh-pages');
var getOutdatedBranches = require('./complexCleanupStep');

ghpages.publish(
  'dist',
  {
    async beforeAdd(git) {
        git.rm(await getOutdatedBranches());
    }
  },
  (err) => { /*...*/ }
);

cli

gh-pages --beforeAdd="./myCustomScript.js"

Let me know what you think about this. I'd happily submit a PR.

@Xiphe Xiphe changed the title Support running a custom script inside the tmp folder Support running a custom script before adding and committing Jan 29, 2020
@Xiphe
Copy link
Contributor Author

Xiphe commented Feb 13, 2020

@tschaub would you be interested in me providing a PR for this?

@tschaub
Copy link
Owner

tschaub commented Feb 13, 2020

Can you describe a bit more about what you are trying to accomplish (maybe with an example)?

@Xiphe
Copy link
Contributor Author

Xiphe commented Feb 17, 2020

Yeah sure!

I'm building each branch of a project to a subdirectory of gh-pages using
gh-pages --add --no-history --dest=${CIRCLE_BRANCH} #--... in oder to have previews for every WIP.

Now I want to remove folders of deleted branches in order to not have stale previews that nobody cares about anymore.

@Xiphe
Copy link
Contributor Author

Xiphe commented Feb 17, 2020

Now I really like that gh-pages takes care of all the git stuff. And I really don't want to do another clone/update/push just after gh-pages is finished doing that.

Thats why I thought that some kind of hook would work best for me while not adding to much knowledge about the target project to this tool

@44px
Copy link

44px commented May 19, 2020

Looks like what I need too for the same use-case (per-branch preview with auto cleanup on merge to master).

@Xiphe
Copy link
Contributor Author

Xiphe commented May 20, 2020

As I said I would love to provide a PR for this (I already had this working via monkey-patching).

@tschaub let me know If you think this would be a good addition.

@tschaub
Copy link
Owner

tschaub commented May 20, 2020

Sure.

@airtonix
Copy link

@44px @Xiphe Are either of you able to share how you're using this? I'm specifically interested in

(per-branch preview with auto cleanup on merge to master).

@Xiphe
Copy link
Contributor Author

Xiphe commented Oct 12, 2020

I used this on a propriatorey project from one of my clients, so I can't point you directly. But I just realise that this is good material for a blogpost. I'll write it down and add a link here.

@Xiphe
Copy link
Contributor Author

Xiphe commented Oct 12, 2020

Here is an example repo deploying a jekyll build of each branch to /preview/[branchname] and main branch to /
https://github.com/Xiphe/example-ghpage-feature-preview

@Xiphe
Copy link
Contributor Author

Xiphe commented Oct 13, 2020

Here is the complete walkthrough: https://xiphe.net/blog/automation/preview-every-branch-with-ghpages.html

@gabrielcsapo
Copy link

@Xiphe this is awesome! Super great addition and awesome article.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants