-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathaction.yml
More file actions
88 lines (83 loc) · 2.94 KB
/
Copy pathaction.yml
File metadata and controls
88 lines (83 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: 'Sync to GitLab'
description: 'Automatically sync your GitHub repository with GitLab'
branding:
icon: 'arrow-right'
color: 'orange'
inputs:
gitlab_url:
description: 'The URL of the GitLab repository (e.g., https://gitlab.com/user/repo.git)'
required: true
username:
description: 'Your GitLab username'
required: true
gitlab_pat:
description: 'Your GitLab Personal Access Token with required permissions'
required: true
force_push:
description: 'Whether to force push to GitLab. Defaults to false.'
required: false
default: 'false'
git_lfs:
description: 'Whether to sync Git LFS objects to GitLab. Defaults to false.'
required: false
default: 'false'
runs:
using: 'composite'
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
persist-credentials: false
lfs: ${{ inputs.git_lfs }}
- name: Validate inputs
env:
GITLAB_URL: ${{ inputs.gitlab_url }}
USERNAME: ${{ inputs.username }}
GITLAB_PAT: ${{ inputs.gitlab_pat }}
run: |
errors=()
if [[ -z "$GITLAB_URL" ]]; then
errors+=("gitlab_url is not set. Please add GITLAB_URL to your repository secrets.")
elif [[ ! "$GITLAB_URL" =~ ^https?://[^/]+/.+ ]]; then
errors+=("gitlab_url format is invalid. Expected: https://gitlab.com/user/repo.git")
fi
if [[ -z "$USERNAME" ]]; then
errors+=("username is not set. Please add USERNAME to your repository secrets.")
fi
if [[ -z "$GITLAB_PAT" ]]; then
errors+=("gitlab_pat is not set. Please add GITLAB_PAT to your repository secrets.")
fi
if [[ ${#errors[@]} -gt 0 ]]; then
echo "::error::Configuration Error(s):"
for err in "${errors[@]}"; do
echo "::error:: - $err"
done
echo ""
echo "To fix this, go to Settings > Secrets and variables > Actions in your GitHub repository."
exit 1
fi
echo "All inputs validated successfully."
shell: bash
- name: Push to GitLab
env:
GITLAB_URL: ${{ inputs.gitlab_url }}
USERNAME: ${{ inputs.username }}
GITLAB_PAT: ${{ inputs.gitlab_pat }}
FORCE_PUSH: ${{ inputs.force_push }}
GIT_LFS: ${{ inputs.git_lfs }}
run: |
gitlab_repo_url="${GITLAB_URL#https://}"
gitlab_repo_url_with_credentials="https://${USERNAME}:${GITLAB_PAT}@${gitlab_repo_url}"
echo "::add-mask::$gitlab_repo_url_with_credentials"
git remote add gitlab "$gitlab_repo_url_with_credentials"
branch_name=$(echo "$GITHUB_REF" | sed 's/refs\/heads\///')
if [[ "$GIT_LFS" == "true" ]]; then
git lfs push --all gitlab
fi
push_command="git push gitlab $branch_name"
if [[ "$FORCE_PUSH" == "true" ]]; then
push_command="$push_command --force"
fi
$push_command
shell: bash