Git Product home page Git Product logo

vercel-private-submodule's Introduction

Vercel private submodule ๐Ÿ”’

Short and easy tutorial for using private submodules on Vercel

๐Ÿ’ก [Approach 1 - .gitmodules]

๐Ÿ“‹ Instructions ๐Ÿš€

Edit your .gitmodules to follow this schema:

[submodule "<repo-name>"]
path = <folder-name>
url = https://<github-token>@github.com/<owner-name>/<repo-name>.git

The important part is the <github-token> in https://<github-token>@github.com/<owner-name>/<repo-name>.git

You can use either a classic token or a fine-grained token with necessary permissions.

๐Ÿ’ก TIP: If you dont know how to get it have a look at this

๐Ÿคซ If you don't want to commit the token

Use this trick - add .gitmodules to .gitignore and then put the whole contents of the .gitmodules in a GitHub Secret or a secret on Vercel, and then when installing dependencies and doing setup, do smthn like echo '${{ secrets.GITMODULES }}' > .gitmodules

๐Ÿ” Best to use a fine-grained token with readonly access only to the repos you have as submodules.

๐ŸŽ‰ That's it! ๐ŸŽ‰

๐Ÿค๐Ÿฝ Thanks @FrameMuse [Issue: #7]


๐Ÿ’ก [Approach 2 - Script]

๐Ÿ“‹ Step by step ๐Ÿš€

  • copy the ./vercel-submodule-workaround.sh to the root of your project

  • make sure the file is executable - run this command:

    chmod u+x vercel-submodule-workaround.sh
  • in your package.json add a script:

    {
        "scripts":{
            "vercel-install": "./vercel-submodule-workaround.sh && yarn --ignore-scripts --production=false",
        }
    }

    Info:

    --production=false ensures that dev-dependencies will be installed, if you dont need your dev-dependencies to install then just delete this flag.

    --ignore-scripts ignores pre and post install scripts if you want the scripts to run delete this flag.

  • Tell Vercel to use vercel-install instead of the defalt install command

    • project -> Settings -> General => Build & Development Settings

    • in INSTALL COMMAND type

    yarn vercel-install 
    # or 
    npm vercel-install
    • toggle OVERRIDE on
  • Create a Github access token

    • Settings -> Developer settings -> Personal access tokens

    • Generate new token

    • set a note (eg. vercel)

    • set expiration to whatever you see fit (eg. No expiration)

    • select repo

      [x] repo - Full control of private repositories

    • copy the generated token

  • Add the token to Vercel Environment Variables

    • Project -> Settings -> Environment Variables

    • add a new variable called GITHUB_ACCESS_TOKEN and with value of the token you just copied

๐ŸŽ‰ That's it! ๐ŸŽ‰


+ Post Scriptum

I haven't added support for multiple submodules but it should be easy enough, try edditing this part and then the rest of the script.

# get submodule commit
output=`git submodule status --recursive` # get submodule info
no_prefix=${output#*-} # get rid of the prefix
COMMIT=${no_prefix% *} # get rid of the suffix

vercel-private-submodule's People

Contributors

beeinger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vercel-private-submodule's Issues

How can I fetch the most recent commit from my private submodule every time I redeploy the project on vercel?

Hi! Sorry, I'm new to this, just trying to figure out how to use this script, I'd really appreciate some help!

My goal is to make this script fetch the most recent commit from my private git submodule every time I redeploy the vercel project.

Strangely, if I push changes to my private submodule, and then redeploy the project, it still fetches the old commit (I think that's the one it fetched when I deployed the project for the first time).

I don't know much about private git submodules (or this script), and I think I'm making some simple mistake. Can you help me figure out what am I doing wrong?

Add instructions to update the vercel-submodule-workaround

For me when following the approach as outlined in the Readme it didn't work and I had to update a few things in the setup script.

Specifically, things outlined in this comment:
https://github.com/orgs/vercel/discussions/44#discussioncomment-3391318

I.e.
Instead of:

git fetch --depth=1 origin $COMMIT # fetch only the required version
git checkout $COMMIT # checkout on the right commit

I used:

git fetch origin
git checkout main 
npm install

and I also updated the references for the variables at the beginning of the script accordingly

# github submodule repo address without https:// prefix
SUBMODULE_GITHUB=path to your own, don't forget the .git bit at the end

# .gitmodules submodule path
SUBMODULE_PATH=this can be copied from the gitmodules file

"fatal: You are on a branch yet to be born"

I'm following the instructions, trying to fetch the private submodule, and getting an error:

fatal: You are on a branch yet to be born

Do you know how I could debug/diagnose it, and figure out what am I doing wrong?

`.gitmodules` Approach

I found out that just passing your API key in url param right in .gitmodules acts the same as your whole script.
So your script is kinda unnecessary. Tell me if i'm wrong, sorry for that in advance if so.

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.