Skip to content

Commit 3830789

Browse files
Merge pull request #9 from whyakari/main
[FEATURE] Added parameter 'branch'
2 parents a228c61 + cd4459d commit 3830789

File tree

3 files changed

+84
-6
lines changed

3 files changed

+84
-6
lines changed

.github/workflows/test_action.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
name: Clone Public Repository Workflow
3+
4+
on:
5+
push:
6+
schedule:
7+
- cron: '0 3 * * *'
8+
workflow_dispatch:
9+
10+
jobs:
11+
12+
job-public-repo-ubuntu:
13+
runs-on: ubuntu-latest
14+
steps:
15+
16+
- name: Clone GuillaumeFalourd/poc-github-actions PUBLIC repository
17+
uses: whyakari/github-repo-action@v3.1
18+
with:
19+
depth: 1
20+
branch: 'main'
21+
owner: 'GuillaumeFalourd'
22+
repository: 'poc-github-actions'
23+
24+
- name: Access cloned repository content
25+
run: |
26+
echo "ROOT"
27+
ls -la
28+
echo "CLONED REPO"
29+
cd poc-github-actions
30+
ls -la
31+
32+
job-public-repo-macos:
33+
runs-on: macos-latest
34+
steps:
35+
36+
- name: Clone GuillaumeFalourd/poc-github-actions PUBLIC repository
37+
uses: whyakari/github-repo-action@v3.1
38+
with:
39+
depth: 1
40+
branch: 'main'
41+
owner: 'GuillaumeFalourd'
42+
repository: 'poc-github-actions'
43+
44+
- name: Access cloned repository content
45+
run: |
46+
echo "ROOT"
47+
ls -la
48+
echo "CLONED REPO"
49+
cd poc-github-actions
50+
ls -la
51+
52+
job-public-repo-windows:
53+
runs-on: windows-latest
54+
steps:
55+
56+
- name: Clone GuillaumeFalourd/poc-github-actions PUBLIC repository
57+
uses: whyakari/clone-github-repo-action@main
58+
with:
59+
depth: 1
60+
branch: 'main'
61+
owner: 'GuillaumeFalourd'
62+
repository: 'poc-github-actions'
63+
64+
- name: Access cloned repository content
65+
run: |
66+
echo "ROOT"
67+
ls -la
68+
echo "CLONED REPO"
69+
cd poc-github-actions
70+
ls -la
71+
shell: bash

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Field | Mandatory | Observation
2222
------------ | ------------ | -------------
2323
**owner** | YES | Ex: `octocat`
2424
**repository** | YES | Ex: `clone-github-repo-action` |
25+
**branch** | NO | 'main' Ex: clone branch main (default) if not defined arg
2526
**depth** | NO | 1 `Ex: most recent commit`
2627
**access-token** | NO | [How to create a PAT](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token)
2728

@@ -37,6 +38,7 @@ You can use one of those as reference:
3738
uses: GuillaumeFalourd/clone-github-repo-action@v2.1
3839
with:
3940
depth: 1
41+
branch: 'main'
4042
owner: 'GuillaumeFalourd'
4143
repository: 'poc-github-actions'
4244
```

action.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: 'Clone Github Repo Action'
1+
name: 'Clone Github Repo'
22

33
description: "Github Action to clone a public or private Github repository and access its content on others repositories' workflows."
44

@@ -16,6 +16,10 @@ inputs:
1616
description: 'Depth of the clone (default: full history)'
1717
required: false
1818
default: ""
19+
branch:
20+
description: 'Branch name (default: main)'
21+
required: false
22+
default: "main"
1923

2024
runs:
2125
using: 'composite'
@@ -24,21 +28,21 @@ runs:
2428
run: |
2529
if [ -z "${{ inputs.access-token }}" ]; then
2630
if [ -z "${{ inputs.depth }}" ]; then
27-
git clone https://github.com/${{ inputs.owner }}/${{ inputs.repository }}.git
31+
git clone --branch "${{ inputs.branch }}" https://github.com/${{ inputs.owner }}/${{ inputs.repository }}.git
2832
else
29-
git clone --depth="${{ inputs.depth }}" https://github.com/${{ inputs.owner }}/${{ inputs.repository }}.git
33+
git clone --branch "${{ inputs.branch }}" --depth="${{ inputs.depth }}" https://github.com/${{ inputs.owner }}/${{ inputs.repository }}.git
3034
fi
3135
else
3236
if [ -z "${{ inputs.depth }}" ]; then
33-
git clone https://${{ inputs.access-token }}@github.com/${{ inputs.owner }}/${{ inputs.repository }}.git
37+
git clone --branch "${{ inputs.branch }}" https://${{ inputs.access-token }}@github.com/${{ inputs.owner }}/${{ inputs.repository }}.git
3438
else
35-
git clone --depth="${{ inputs.depth }}" https://${{ inputs.access-token }}@github.com/${{ inputs.owner }}/${{ inputs.repository }}.git
39+
git clone --branch "${{ inputs.branch }}" --depth="${{ inputs.depth }}" https://${{ inputs.access-token }}@github.com/${{ inputs.owner }}/${{ inputs.repository }}.git
3640
fi
3741
fi
3842
3943
if [ -d "${{ inputs.repository }}" ]; then
4044
echo "Cloned ${{ inputs.repository }} repository successfully."
41-
echo "Access the repository content using \"cd ${{ inputs.repository }}\"."
45+
echo "Access the repository content using \"cd ${{ inputs.repository }}.\""
4246
else
4347
echo "Error: Couldn't clone ${{ inputs.repository }} repository. Check the inputs or the PAT scope."
4448
exit 1
@@ -48,3 +52,4 @@ runs:
4852
branding:
4953
icon: 'download'
5054
color: 'blue'
55+

0 commit comments

Comments
 (0)