Sync Internal and Public Repos #71
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: ["Release"] | |
types: | |
- completed | |
jobs: | |
sync-repos: | |
name: Sync Internal and Public Repos | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Public Repo | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.HCP_SDK_PIPELINE_TOKEN }} | |
path: public | |
- name: Checkout Internal Repo | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 | |
with: | |
token: ${{ secrets.HCP_SDK_PIPELINE_TOKEN }} | |
repository: hashicorp/terraform-provider-hcp-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/README.md | |
ls -al public | |
# Copy important files from internal repo | |
sudo cp -a internal/.git temp/.git | |
cp -a internal/.github temp/.github | |
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-provider)" | |
[[ -n $sync_branch_exists ]] && git push origin --delete sync-public-and-internal-provider | |
git checkout -b sync-public-and-internal-provider | |
git add -A | |
git commit -m "Sync with public Provider" | |
git push --set-upstream origin sync-public-and-internal-provider | |
- 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 Provider" | |
PR_BODY: "This is an auto-generated PR updating the internal HCP Terraform Provider with the latest changes from the open source HCP Terraform Provider." | |
PR_SOURCE: "sync-public-and-internal-provider" | |
PR_TARGET: "main" | |
GITHUB_TOKEN: ${{ secrets.HCP_SDK_PIPELINE_TOKEN }} |