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

Add git-lfs to setup process #758

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ trim_trailing_whitespace = true
[Makefile]
indent_size = 4
indent_style = tab

[Dockerfile]
indent_size = 4
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Note that the `GITHUB_TOKEN` that is created by the runner might not inherently
- [⭐️ Set Git username and email](#%EF%B8%8F-set-git-username-and-email)
- [⭐️ Set custom commit message](#%EF%B8%8F-set-custom-commit-message)
- [⭐️ Create Git tag](#%EF%B8%8F-create-git-tag)
- [⭐️ Upload large files with Git LFS](#%EF%B8%8F-upload-large-files-with-git-lfs)
- [Tips and FAQ](#tips-and-faq)
- [⭐️ Create SSH Deploy Key](#%EF%B8%8F-create-ssh-deploy-key)
- [⭐️ First Deployment with `GITHUB_TOKEN`](#%EF%B8%8F-first-deployment-with-github_token)
Expand Down Expand Up @@ -523,7 +524,44 @@ v1.2.3 # Tag on the main branch
<a href="#table-of-contents">Back to TOC ☝️</a>
</div>

### ⭐️ Upload large files with Git LFS

If you are using [Git LFS](https://git-lfs.github.com/) as an option to manage files larger than 100MB in your repository, you can push these to the deployed site.

It is expected that you would run your checkout action with `lfs` enabled (see below for an example).

You will also need to make sure that your build tool includes the `.gitattributes` file in its output.

```yaml
name: GitHub Pages

on:
push:
branches:
- main
tags:
- 'v*.*.*'

jobs:
deploy:
runs-on: ubuntu-20.04
permissions:
contents: write
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
steps:
- name: Checkout
- uses: actions/checkout@v3
with:
lfs: 'true'

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./public
lfs: 'true'
```

## Tips and FAQ

Expand Down
4 changes: 4 additions & 0 deletions __tests__/get-inputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function getInputsLog(authMethod: string, inps: Inputs): string {
[INFO] EnableJekyll (DisableNoJekyll): ${inps.DisableNoJekyll}
[INFO] CNAME: ${inps.CNAME}
[INFO] ExcludeAssets ${inps.ExcludeAssets}
[INFO] Lfs: ${inps.Lfs}
`;
}

Expand Down Expand Up @@ -125,6 +126,7 @@ describe('getInputs()', () => {
expect(inps.DisableNoJekyll).toBe(false);
expect(inps.CNAME).toMatch('');
expect(inps.ExcludeAssets).toMatch('.github');
expect(inps.Lfs).toBe(false);
});

test('get spec inputs', () => {
Expand All @@ -147,6 +149,7 @@ describe('getInputs()', () => {
process.env['INPUT_DISABLE_NOJEKYLL'] = 'true';
process.env['INPUT_CNAME'] = 'github.com';
process.env['INPUT_EXCLUDE_ASSETS'] = '.github';
process.env['INPUT_LFS'] = 'false';

const inps: Inputs = getInputs();

Expand All @@ -169,6 +172,7 @@ describe('getInputs()', () => {
expect(inps.DisableNoJekyll).toBe(true);
expect(inps.CNAME).toMatch('github.com');
expect(inps.ExcludeAssets).toMatch('.github');
expect(inps.Lfs).toBe(false);
});

test('get spec inputs enable_jekyll', () => {
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@ inputs:
description: 'Set files or directories to exclude from a publish directory.'
required: false
default: '.github'
lfs:
description: 'Whether to use Git-LFS to upload files'
required: false
default: 'false'
4 changes: 4 additions & 0 deletions src/get-inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export function showInputs(inps: Inputs): void {
[INFO] EnableJekyll (DisableNoJekyll): ${inps.DisableNoJekyll}
[INFO] CNAME: ${inps.CNAME}
[INFO] ExcludeAssets ${inps.ExcludeAssets}
[INFO] Lfs: ${inps.Lfs}
`);
}

Expand All @@ -48,9 +49,12 @@ export function getInputs(): Inputs {
useBuiltinJekyll = true;
}

const enableLfs: boolean = isBoolean(core.getInput('lfs'));

const inps: Inputs = {
DeployKey: core.getInput('deploy_key'),
GithubToken: core.getInput('github_token'),
Lfs: enableLfs,
PersonalToken: core.getInput('personal_token'),
PublishBranch: core.getInput('publish_branch'),
PublishDir: core.getInput('publish_dir'),
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface Inputs {
readonly DeployKey: string;
readonly GithubToken: string;
readonly Lfs: boolean;
readonly PersonalToken: string;
readonly PublishBranch: string;
readonly PublishDir: string;
Expand Down
3 changes: 3 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ export async function run(): Promise<void> {
core.endGroup();

core.startGroup('Setup Git config');
if (inps.Lfs) {
await exec.exec('git', ['lfs', 'install', '--local']);
}
try {
await exec.exec('git', ['remote', 'rm', 'origin']);
} catch (e) {
Expand Down