-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: mirror action creates repo if it doesn't exist (#32)
- Loading branch information
1 parent
b836c86
commit 29316eb
Showing
1 changed file
with
57 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,27 +2,81 @@ on: | |
workflow_call: | ||
inputs: | ||
repo_name: | ||
description: "Name of the repository to mirror to" | ||
required: true | ||
type: string | ||
secrets: | ||
ssh_private_key: | ||
description: "SSH private key for pushing to the mirror repository" | ||
required: true | ||
ghe_token: | ||
description: "GitHub Enterprise token for creating the mirror repository if it does not exist" | ||
required: false | ||
|
||
jobs: | ||
mirror: | ||
name: mirror | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- uses: pixta-dev/repository-mirroring-action@v1 | ||
|
||
- name: Check if token was provided | ||
id: check_token | ||
continue-on-error: true | ||
run: | | ||
if [ -z "${{ secrets.ghe_token }}" ]; then | ||
echo "GHE token was not provided" | ||
exit 1 | ||
fi | ||
- name: Get default branch | ||
id: get_default_branch | ||
if: ${{ steps.check_token.outcome == 'success' }} | ||
run: | | ||
echo "DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef --jq .defaultBranchRef.name)" >> "$GITHUB_ENV" | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Check if target mirror repository exists | ||
# Only run this step if a token was provided | ||
if: ${{ steps.check_token.outcome == 'success' }} | ||
continue-on-error: true | ||
id: check_repo | ||
run: | | ||
gh repo view $GH_HOST/skills-network-mirror/${{ inputs.repo_name }} > /dev/null | ||
env: | ||
GH_ENTERPRISE_TOKEN: ${{ secrets.ghe_token }} | ||
GH_HOST: github.ibm.com | ||
|
||
- name: Create repository since it doesn't exist | ||
if: ${{ steps.check_repo.outcome == 'failure' }} | ||
run: | | ||
gh repo create $GH_HOST/skills-network-mirror/${{ inputs.repo_name }} --internal --disable-wiki | ||
env: | ||
GH_ENTERPRISE_TOKEN: ${{ secrets.ghe_token }} | ||
GH_HOST: github.ibm.com | ||
|
||
- name: Mirror repository | ||
uses: pixta-dev/repository-mirroring-action@v1 | ||
with: | ||
target_repo_url: | ||
${{ format('[email protected]:{0}/{1}.git', 'skills-network-mirror', inputs.repo_name) }} | ||
ssh_private_key: | ||
${{ secrets.ssh_private_key }} | ||
- run: | | ||
|
||
- name: Set default branch | ||
if: ${{ steps.get_default_branch.conclusion == 'success' }} | ||
run: | | ||
gh repo edit $GH_HOST/skills-network-mirror/${{ inputs.repo_name }} --default-branch=${{ env.DEFAULT_BRANCH }} | ||
env: | ||
GH_ENTERPRISE_TOKEN: ${{ secrets.ghe_token }} | ||
GH_HOST: github.ibm.com | ||
|
||
- name: Fix whitesource | ||
run: | | ||
mkdir -p ~/.ssh | ||
echo "${{ secrets.ssh_private_key }}" > ~/.ssh/id_rsa | ||
chmod 600 ~/.ssh/id_rsa | ||
|