Skip to content

Commit

Permalink
HCE-24: Sync Internal and Public SDK Repos Automatically (#157)
Browse files Browse the repository at this point in the history
* try checkouts

* changelog

* add pr dispatch

* add runs on

* add logging

* add sync

* refactor

* change dispatch

* configure git

* sudo

* capital A

* change to workflow dispatch

* reset internal directory

* save doc stuff

* typo

* yaml not yml

* dispatch on successful release

* Update .github/workflows/sync-internal-and-public.yml

Co-authored-by: Brenna Hewer-Darroch <21015366+bcmdarroch@users.noreply.github.com>

* retain script

* don't resync

* omit pull_request trigger

* regen with scripts

* remove pr trigger

* Update .github/workflows/sync-internal-and-public.yml

Co-authored-by: Brenna Hewer-Darroch <21015366+bcmdarroch@users.noreply.github.com>

Co-authored-by: Brenna Hewer-Darroch <21015366+bcmdarroch@users.noreply.github.com>
  • Loading branch information
itsjaspermilan and bcmdarroch authored Jan 4, 2023
1 parent 6a91a16 commit ec1a296
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
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 }}

0 comments on commit ec1a296

Please sign in to comment.