GitHub Action
LeetCode Sync
GitHub Action for automatically syncing LeetCode submissions to a GitHub repository.
- Syncs accepted solutions from LeetCode to the default branch of the GitHub repo
- Only syncs solutions that have not been synced before
- Uploads the latest accepted solution for a single problem if there are multiple submissions per day
-
Login to LeetCode and obtain the
csrftoken
andLEETCODE_SESSION
cookie values.- After logging in, right-click on the page and press
Inspect
. - Refresh the page.
- Look for a network request to https://leetcode.com.
- Look under
Request Headers
for thecookie:
attribute to find the values.
- After logging in, right-click on the page and press
-
Create a new GitHub repository to host the LeetCode submissions.
- It can be either private or public.
-
Add the values from step 1 as GitHub secrets, e.g.
LEETCODE_CSRF_TOKEN
andLEETCODE_SESSION
. -
Add a workflow file with this action under the
.github/workflows
directory, e.g.sync_leetcode.yml
.Example workflow file:
name: Sync Leetcode on: workflow_dispatch: schedule: - cron: '0 8 * * 6' jobs: build: runs-on: ubuntu-latest steps: - name: Sync uses: joshcai/leetcode-sync@v1.2 with: github-token: ${{ github.token }} leetcode-csrf-token: ${{ secrets.LEETCODE_CSRF_TOKEN }} leetcode-session: ${{ secrets.LEETCODE_SESSION }}
-
Run the workflow by going to the
Actions
tab, clicking the action name, e.g.Sync Leetcode
, and then clickingRun workflow
. The workflow will also automatically run once a week by default (can be configured via thecron
parameter).
github-token
(required): The GitHub access token for pushing solutions to the repositoryleetcode-csrf-token
(required): The LeetCode CSRF token for retrieving submissions from LeetCodeleetcode-session
(required): The LeetCode session value for retrieving submissions from LeetCodefilter-duplicate-secs
: Number of seconds after an accepted solution to ignore other accepted solutions for the same problem, default: 86400 (1 day)
This likely means that you hit a rate limit when committing to GitHub (this may happen if you have over ~300 submissions initially). Since the syncer writes in reverse chronological order, it should pick up syncing submissions from where it left off on the next run of the workflow, so just retry the workflow manually after some time.
Special thanks to the following people who helped beta test this GitHub Action and gave feedback on improving it: