generated from ibm-client-engineering/solution-template
-
Notifications
You must be signed in to change notification settings - Fork 2
159 lines (150 loc) · 7.06 KB
/
sync.yaml
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
name: Sync with GitHub Enterprise
env:
GITHUB_TOKEN: ${{ secrets.GH_ENTERPRISE_TOKEN }}
GHE_USER: ${{ vars.SYNC_USER }}
GHE_FULL_USER: ${{ vars.SYNC_USER_NAME }}
ENTERPRISE_URL: ${{ vars.ENTERPRISE_GIT_URL }}
ENTERPRISE_EMAIL: ${{ vars.SYNC_USER_EMAIL }}
DEFAULT_TEMPLATE: ${{ vars.REPO_TEMPLATE }}
COMMIT_MESSAGE: Pushing updates from Public to Enterprise
COMMIT_AUTHOR: Friendly Neighborhood CEBOT
CEBOT_GH_TRAVIS_TOKEN: ${{ secrets.CEBOT_GH_TRAVIS_TOKEN }}
CEBOT_TRAVIS_API_KEY: ${{ secrets.CEBOT_TRAVIS_API_KEY }}
TRAVIS_API_ENDPOINT: ${{ vars.TRAVIS_API_ENDPOINT }}
ENTERPRISE_PAGES_URL: ${{ vars.ENTERPRISE_PAGES_URL }}
on:
push:
branches:
- main
jobs:
verify_and_mirror:
runs-on: ubuntu-latest
steps:
- name: Check if remote enterprise repo exists
id: repocheck
run: git ls-remote https://${{ env.GHE_USER }}:${{ env.GITHUB_TOKEN }}@${{ env.ENTERPRISE_URL }}/${{ github.repository }} -q --exit-code
- name: Create remote repo
if: ${{ failure() && steps.repocheck.conclusion == 'failure' }}
run: |
echo ${{ env.GITHUB_TOKEN }} > /tmp/token.txt
gh auth login -p https -h ${{ env.ENTERPRISE_URL }} --with-token < /tmp/token.txt
gh repo create --public ${{ github.repository }}
# - name: Checkout repo and all branches to stage
# id: checkout
## if: ${{ failure() && steps.repocheck.conclusion == 'failure' }}
# uses: actions/checkout@v4
# with:
# repository: ${{ github.repository }}
# fetch-depth: 0
# - name: Mirror the repo up to our internal github
# id: mirror
## if: ${{ failure() && steps.check_directory.conclusion != 'failure' }}
# uses: yesolutions/mirror-action@master
# with:
# REMOTE: 'https://${{ env.ENTERPRISE_URL }}/${{ github.repository }}'
# GIT_USERNAME: ${{ env.GHE_USER }}
# GIT_PASSWORD: ${{ env.GITHUB_TOKEN }}
- name: Set repo name as an env var
id: repo_name
# if: ${{ failure() && steps.check_directory.conclusion != 'failure' }}
run: |
echo ${{ github.repository }}| awk -F/ '{print "REPO_NAME="$2}' >> "$GITHUB_OUTPUT"
- name: Set Travis Vars
id: travis
# if: ${{ failure() && steps.check_directory.conclusion != 'failure' }}
env:
REPO_NAME: ${{ steps.repo_name.outputs.REPO_NAME }}
run: |
curl -X POST \
-H "Content-Type: application/json" \
-H "Travis-API-Version: 3" \
-H "Authorization: token ${{ env.CEBOT_TRAVIS_API_KEY }}" \
-d '{ "env_var.name": "ORG", "env_var.value": "${{ github.repository_owner }}", "env_var.public": true }' \
${{ env.TRAVIS_API_ENDPOINT }}/repo/${{ github.repository_owner }}%2F${{ env.REPO_NAME }}/env_vars
curl -X POST \
-H "Content-Type: application/json" \
-H "Travis-API-Version: 3" \
-H "Authorization: token ${{ env.CEBOT_TRAVIS_API_KEY }}" \
-d '{ "env_var.name": "REPO", "env_var.value": "${{ env.REPO_NAME }}", "env_var.public": true }' \
${{ env.TRAVIS_API_ENDPOINT }}/repo/${{ github.repository_owner }}%2F${{ env.REPO_NAME }}/env_vars
curl -X POST \
-H "Content-Type: application/json" \
-H "Travis-API-Version: 3" \
-H "Authorization: token ${{ env.CEBOT_TRAVIS_API_KEY }}" \
-d '{ "env_var.name": "GITHUB_TOKEN", "env_var.value": "${{ env.CEBOT_GH_TRAVIS_TOKEN }}", "env_var.public": false }' \
${{ env.TRAVIS_API_ENDPOINT }}/repo/${{ github.repository_owner }}%2F${{ env.REPO_NAME }}/env_vars
curl -X POST \
-H "Content-Type: application/json" \
-H "Travis-API-Version: 3" \
-H "Authorization: token ${{ env.CEBOT_TRAVIS_API_KEY }}" \
-d '{ "env_var.name": "PAGES_URL", "env_var.value": "${{ env.ENTERPRISE_PAGES_URL }}", "env_var.public": true }' \
${{ env.TRAVIS_API_ENDPOINT }}/repo/${{ github.repository_owner }}%2F${{ env.REPO_NAME }}/env_vars
# update:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout Enterprise repo and all branches
# uses: actions/checkout@v4
# with:
# github-server-url: https://${{ env.GHE_USER }}@${{ env.ENTERPRISE_URL }}
# repository: ${{ github.repository }}
# token: ${{ env.GITHUB_TOKEN }}
# - name: See if dashboard directory exists and create if it doesn't
# id: check_directory
# uses: JJ/files-present-action@releases/v1
# with:
# files: 'dashboard/README.md'
# - name: No Dashboard
# if: ${{ failure() && steps.check_directory.conclusion == 'failure' }}
# run: |
# git config --local user.name ${{ env.GHE_USER }}
# git config --local user.email "${{ env.GHE_USER }}@users.noreply.github.com"
# mkdir ./dashboard
# echo "README" > ./dashboard/README.md
# git add ./dashboard
# git commit -m "Dashboard directory created!"
# git push
## git remote set-url origin https://${{ env.GHE_USER }}:${{ env.GITHUB_TOKEN }}@${{ env.ENTERPRISE_URL }}/${{ github.repository }}
## git push
## - name: Push changes # push the output folder to your repo
## if: ${{ failure() && steps.check_directory.conclusion == 'failure' }}
## uses: ad-m/github-push-action@master
### uses: justjavac/action-gh-push@v1
## with:
## GITHUB_TOKEN: ${{ env.GITHUB_TOKEN }}
## repository: 'https://${{ env.ENTERPRISE_URL }}/${{ github.repository }}'
## force: true
# sync:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout our public repo
# uses: actions/checkout@v4
# with:
# repository: ${{ github.repository }}
# fetch-depth: 0
# path: public
## - name: Checkout our enterprise repo
## uses: actions/checkout@v4
## with:
## github-server-url: https://${{ env.GHE_USER }}@${{ env.ENTERPRISE_URL }}
## repository: ${{ github.repository }}
## fetch-depth: 0
## token: ${{ env.GITHUB_TOKEN }}
## path: enterprise
# - name: Clone our enterprise repo
# run: |
# git config --global user.name "${{ env.COMMIT_AUTHOR }}"
# git config --global user.email ${{ env.GHE_USER }}@users.noreply.github.com
# git clone https://${{ env.GHE_USER}}:${{ env.GITHUB_TOKEN }}@${{ env.ENTERPRISE_URL }}/${{ github.repository }}.git enterprise
# - name: Copy over all changed files from public to enterprise
# run: |
# rsync -auvr --exclude '.git' --exclude 'docusaurus.config.js' --exclude '.travis.yml' public/* enterprise
# cd enterprise
# git config --global user.name "${{ env.COMMIT_AUTHOR }}"
# git config --global user.email ${{ env.GHE_USER }}@users.noreply.github.com
# git add .
# git commit -a -m "${{ env.COMMIT_MESSAGE }}"
# - name: Push the changes to enterprise github
# uses: ad-m/github-push-action@master
# with:
# github_token: ${{ env.GITHUB_TOKEN }}
#