Skip to content

New Featuer - Add branch selector #6

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

Open
wants to merge 6 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
50 changes: 49 additions & 1 deletion .github/workflows/public-repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,59 @@ jobs:
owner: 'GuillaumeFalourd'
repository: 'poc-github-actions'

- name: Access cloned repository content
run: |
ls .

job-public-repo-ubuntu-branch:
runs-on: ubuntu-latest
steps:

- name: Clone GuillaumeFalourd/poc-github-actions PUBLIC repository
uses: lipeilin375/clone-github-repo-action@main
with:
owner: GuillaumeFalourd
repository: poc-github-actions
branch: dev

- name: Access cloned repository content
run: |
echo "ROOT"
ls -la
echo "CLONED REPO"
cd poc-github-actions
ls -la

job-public-repo-macos-branch:
runs-on: macos-latest
steps:

- name: Clone GuillaumeFalourd/poc-github-actions PUBLIC repository
uses: lipeilin375/clone-github-repo-action@main
with:
owner: GuillaumeFalourd
repository: poc-github-actions
branch: dev

- name: Access cloned repository content
run: |
echo "ROOT"
ls -la
echo "CLONED REPO"
cd poc-github-actions
ls -la
shell: bash

job-public-repo-windows-branch:
runs-on: windows-latest
steps:

- name: Clone GuillaumeFalourd/poc-github-actions PUBLIC repository
uses: lipeilin375/clone-github-repo-action@main
with:
owner: GuillaumeFalourd
repository: poc-github-actions
branch: dev

- name: Access cloned repository content
run: |
ls .
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Field | Mandatory | Observation
**owner** | YES | Ex: `octocat`
**repository** | YES | Ex: `clone-github-repo-action`
**access-token** | NO | [How to create a PAT](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token)
**branch** | NO | Ex: `main`

You can use one of those as reference:

Expand Down
53 changes: 28 additions & 25 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,39 @@ name: 'Clone Github Repo Action'
description: "Github Action to clone a public or private Github repository and access its content on others repositories' workflows."

inputs:
owner:
description: 'Repository Owner'
required: true
repository:
description: 'Repository name'
required: true
access-token:
description: 'PAT with repository scope (https://github.com/settings/tokens)'
required: false
owner:
description: 'Repository Owner'
required: true
repository:
description: 'Repository name'
required: true
access-token:
description: 'PAT with repository scope (https://github.com/settings/tokens)'
required: false
branch:
description: 'Repository Branch'
required: false

runs:
using: 'composite'
steps:
using: 'composite'
steps:
- name: Missing required value
if: ${{ github.event.inputs.owner == '' || github.event.inputs.repository == '' }}
run: echo "Missing Required Value!"
shell: bash
- name: Clone repository
if: ${{ github.event.inputs.owner != '' && github.event.inputs.repository != '' }}
run: |
if [ -z "${{ inputs.access-token }}" ]; then
git clone https://github.com/${{ inputs.owner }}/${{ inputs.repository }}.git
else
git clone https://${{ inputs.access-token }}@github.com/${{ inputs.owner }}/${{ inputs.repository }}.git
fi

if [ -d "${{ inputs.repository }}" ]; then
echo "Cloned ${{ inputs.repository }} repository successfully."
echo "Access the repository content using \"cd ${{ inputs.repository }}\"."
if [[ -z ${{ github.event.inputs.access-token }} && -z ${{ github.event.inputs.branch }} ]]; then
git clone https://github.com/${{ inputs.owner }}/${{ inputs.repository }}.git
elif [[ -z ${{ github.event.inputs.access-token }} && -n ${{ github.event.inputs.branch }} ]]; then
git clone https://github.com/${{ inputs.owner }}/${{ inputs.repository }}.git -b ${{ inputs.branch }}
elif [[ -n ${{ github.event.inputs.access-token }} && -z ${{ github.event.inputs.branch }} ]]; then
git clone https://${{ inputs.access-token }}@github.com/${{ inputs.owner }}/${{ inputs.repository }}.git
else
echo "Error: Couldn't clone ${{ inputs.repository }} repository. Check the inputs or the PAT scope."
exit 1
fi
git clone https://${{ inputs.access-token }}@github.com/${{ inputs.owner }}/${{ inputs.repository }}.git -b ${{ inputs.branch }}
shell: bash

branding:
icon: 'download'
color: 'blue'
icon: 'download'
color: 'blue'