Git Product home page Git Product logo

overleaf_sync_with_git's Introduction

Overleaf Sync with Git

๐Ÿค– A GitHub action to take backups from OverLeaf which is an Online LaTeX Editor.

Usage

Ensure that you have set OVERLEAF_COOKIE and OVERLEAF_PROJECT_ID as GitHub secrets. Head over to this link to get more info on how to add secrets to a GitHub repo.

You may also need to edit your project settings to allow workflows to write to your repository. Click on Settings -> then Actions and ensure that under Workflow permissions you've provided Read and write permissions to workflow. image

Once you have set the secrets. Just create a new workflow file in .github/workflows/FILE_NAME.yml and add the following content.

name: Overleaf Sync with Git
on:
  schedule:
    - cron: "0/5 * * * *"
  push:
  workflow_dispatch:
      
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: Delete Old Artifacts
      uses: actions/github-script@v6
      id: artifact
      with:
        script: |
          const res = await github.rest.actions.listArtifactsForRepo({
            owner: context.repo.owner,
            repo: context.repo.repo,
          })

          res.data.artifacts
            .forEach(({ id }) => {
              github.rest.actions.deleteArtifact({
                owner: context.repo.owner,
                repo: context.repo.repo,
                artifact_id: id,
              })
            })

    - name: Fetch the latest version from overleaf server
      uses: subhamx/overleaf_sync_with_git@master
      with:
        OVERLEAF_PROJECT_ID: ${{ secrets.OVERLEAF_PROJECT_ID }}
        OVERLEAF_COOKIE: ${{ secrets.OVERLEAF_COOKIE }}

    - name: Upload to Project Artifacts
      uses: actions/upload-artifact@v4
      with:
        name: project
        path: ./artifacts/

    - uses: actions/checkout@v2
      with:
        path: repo/
    
    - run: |
        cd repo/
        mkdir -p overleaf_remote_src
        cp -r ../artifacts/* ./overleaf_remote_src
        git config user.name "Overleaf Sync Bot"
        git config user.email "[email protected]"
        git add .
        if [[ $(git diff HEAD --stat) == '' ]]; then (echo 'Working tree is clean') 
        else (git commit -m "Sync with overleaf remote"  && git push) fi

Getting the required parameters

OVERLEAF_PROJECT_ID

The OVERLEAF_PROJECT_ID secret can be copied from the Overleaf URL of the project you want to sync. The project ID of the following URL https://www.overleaf.com/project/12345a6b7890cdef1a23456b would be 12345a6b7890cdef1a23456b

OVERLEAF_COOKIE

This value is a bit trickier to find. It is used to authenticate the action against the Overleaf servers. It is part of the cookie that Overleaf sets in your browser after you successfully login. The process of extracting the required value differs from browser to browser.

In either case open the developer console (Hotkey F12). For Firefox look for the Storage tab and then select Cookies. For Edge the same setting can be found under Application and then Storage -> Cookies. Look for a cookie with the name overleaf_session2 and copy its value.

IMPORTANT: I would recommend that after you copy overleaf_session2 cookie and put it in the GitHub actions secret, please delete the cookie from the browser. And then start a new browser session (by logging in again) if required. Please do not logout, it will make overleaf revoke the credentials. If you follow the above point, then the cookie should remain active for atleast 2 months, and the workflow should work without any issues. We've tested it in early 2023 by working a sample workflow for couple of months, and you can find the insights here.

In the following case, please put s%3A3xxaFrMMXWi1xxxtm23BjBYJTc8GAb7P.xxyxxzhxxrPJxxovoxxaafnxx9ZorxxP6YxxzxfxxIo as the OVERLEAF_COOKIE value.

image

Optional Parameters

OVERLEAF_HOST

The OVERLEAF_HOST parameter can be used to sync with a self-hosted Community Edition or Server Pro Overleaf instance. The parameter defaults to www.overleaf.com, when not set.

To set the value, just add the environment variable to the actions step, as seen below:

    - name: Fetch the latest version from overleaf server
      uses: subhamx/overleaf_sync_with_git@master
      with:
        OVERLEAF_PROJECT_ID: ${{ secrets.OVERLEAF_PROJECT_ID }}
        OVERLEAF_COOKIE: ${{ secrets.OVERLEAF_COOKIE }}
        OVERLEAF_HOST: ${{ secrets.OVERLEAF_HOST }}

overleaf_sync_with_git's People

Contributors

subhamx avatar spyfly avatar emhl avatar fritzjo avatar mattheffnt avatar country-if avatar

Stargazers

Guo Weibin avatar

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.