Sync Internal and Public Repos #140
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
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@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.HCP_SDK_PIPELINE_TOKEN }} | |
path: public | |
- name: Checkout Internal Repo | |
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 | |
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 | |
mkdir -p temp/cmd/transform-swagger | |
cp -a internal/cmd/transform-swagger/* temp/cmd/transform-swagger/ | |
cp internal/README.md temp/README.md | |
cp internal/catalog-info.yaml temp/catalog-info.yaml | |
cp internal/mkdocs.yml temp/mkdocs.yml | |
cp internal/Makefile temp/Makefile | |
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 }} |