Skip to content
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

HCE-24: Sync Internal and Public SDK Repos Automatically #157

Merged
merged 25 commits into from
Jan 4, 2023
Merged
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
3 changes: 3 additions & 0 deletions .changelog/157.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:feature
Automatically sync the public and internal repos.
```
79 changes: 79 additions & 0 deletions .github/workflows/sync-internal-and-public.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Sync Internal and Public Repos

on:
workflow_dispatch:
workflow_run:
workflows: ["Create Release"]
types:
- completed

jobs:
sync-repos:
name: Sync Internal and Public Repos
runs-on: ubuntu-latest
steps:
- name: Checkout Public Repo
uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ secrets.HCP_SDK_PIPELINE_TOKEN }}
path: public

- name: Checkout Internal Repo
uses: actions/checkout@v3
with:
token: ${{ secrets.HCP_SDK_PIPELINE_TOKEN }}
repository: hashicorp/hcp-sdk-go-internal
path: internal

- name: Sync Changes
run: |
# Make a temp directory for the internal repo
mkdir temp

# Remove files from public repo
rm -r public/.git public/.changelog public/.github public/clients public/docs public/README.md public/scripts
ls -al public

# Copy files that should not be changed in internal repo
sudo cp -a internal/.git temp/.git
cp -a internal/.github temp/.github
cp -a internal/clients temp/clients
cp -a internal/docs temp/docs
cp -a internal/scripts temp/scripts
cp internal/README.md temp/README.md
cp internal/catalog-info.yaml temp/catalog-info.yaml
cp internal/mkdocs.yml temp/mkdocs.yml

rm -r internal
mkdir internal

# Sync public with internal
cp -a public/. internal
sudo cp -a temp/. internal

cd internal
git status

- name: Create Branch
run: |
cd internal
git config user.name "HashiCorp Cloud Services"
git config user.email "${{ secrets.HCP_SERVICE_ACCOUNT_EMAIL }}"
sync_branch_exists="$(git ls-remote --heads origin sync-public-and-internal-sdk)"
[[ -n $sync_branch_exists ]] && git push origin --delete sync-public-and-internal-sdk
git checkout -b sync-public-and-internal-sdk
git add -A
git commit -m "Sync with public SDK"
git push --set-upstream origin sync-public-and-internal-sdk

- name: Open PR
run: |
cd internal
gh pr create --title "$PR_TITLE" --body "$PR_BODY" -H "$PR_SOURCE" -B "$PR_TARGET"
env:
PR_TITLE: "[auto] Sync with Public SDK"
PR_BODY: "This is an auto-generated PR updating the internal SDK with the latest changes from the open source SDK. Client changes are excluded."
PR_SOURCE: "sync-public-and-internal-sdk"
PR_TARGET: "main"
GITHUB_TOKEN: ${{ secrets.HCP_SDK_PIPELINE_TOKEN }}