Skip to content

Commit 34aa56e

Browse files
DavidS-ovmactions-user
authored andcommitted
[ENG-2673] Add Copybara and publishing pipeline for Terraform provider and module (#3958)
## Summary - Add Copybara workflows, GoReleaser config, GPG signing, and GitHub Actions release pipelines to publish the Terraform provider and HCL module to public repos and registries - Provision per-repo GitHub Actions secrets (`OP_RO_TOKEN`, `RELEASE_PAT`) via Terraform, following the existing `homebrew-overmind`/`actions` pattern - Public repos ([terraform-provider-overmind](https://github.com/overmindtech/terraform-provider-overmind), [terraform-overmind-aws-source](https://github.com/overmindtech/terraform-overmind-aws-source)) have been created and seeded with workflow files ## Linear Ticket - **Ticket**: [ENG-2673](https://linear.app/overmind/issue/ENG-2673/phase-5-copybara-and-publishing-for-terraform-provider-and-module) — Phase 5: Copybara and Publishing for Terraform Provider & Module - **Purpose**: Set up the full automated release pipeline from monorepo tags to Terraform/OpenTofu registries - **Plan approval**: [ENG-2674](https://linear.app/overmind/issue/ENG-2674/approve-plan-phase-5-copybara-and-publishing-for-terraform-provider) assigned to Lionel Wilson ## Changes ### Copybara (`copy.bara.sky`) Two new workflows: `terraform-provider` (syncs provider + Go libs with import rewriting) and `terraform-aws-source-module` (syncs HCL module with directory flattening). ### Monorepo sync workflows (`.github/workflows/`) - `terraform-provider-sync.yml` — triggers on `terraform-provider/v*` tags - `terraform-aws-source-module-sync.yml` — triggers on `terraform-aws-source-module/v*` tags ### Provider release files (`aws-source/module/provider/`) - `.goreleaser.yml` — cross-platform builds, zip archives, SHA256 checksums, GPG signing - `terraform-registry-manifest.json` — protocol version 6.0 - `.github/workflows/release.yml` — loads GPG key from 1Password, runs GoReleaser - `.github/workflows/finalize-copybara-sync.yml` — runs `go mod tidy`, creates PR - `.github/workflows/tag-on-merge.yml` — creates version tag on merge ### Module release files (`aws-source/module/terraform/`) - `.github/workflows/finalize-copybara-sync.yml` — creates PR (no `go mod tidy`) - `.github/workflows/tag-on-merge.yml` — creates version tag on merge ### Terraform / secrets - `deploy/1password.tf` — 4 new `github_actions_secret` resources for both public repos - `deploy/variables.tf` — new `terraform_provider_release_pat` and `terraform_module_release_pat` variables - `deploy/.env.op`, `deploy/.github/env/op.local.secret`, `.devcontainer/devcontainer.json` — wire new PAT variables through 1Password and devcontainer ### Provider code - `aws-source/module/provider/main.go` — `const version` changed to `var version = "dev"` for GoReleaser ldflags injection ## Before first release The following manual steps remain (documented in the plan): 1. Create 1Password items: `Terraform Provider Release Github Token`, `Terraform Module Release Github Token`, `Terraform Provider GPG Key` 2. Register GPG public key at registry.terraform.io/settings/gpg-keys 3. After merge, `terraform apply` provisions the repo secrets 4. Push monorepo tags to trigger first automated release 5. Enroll in Terraform Registry and OpenTofu Registry Made with [Cursor](https://cursor.com) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Mostly CI/release automation and secret provisioning changes, but misconfiguration could leak or break release/tagging flows for the public Terraform repos. > > **Overview** > Adds end-to-end **Copybara-based publishing pipelines** for the Terraform provider and AWS source Terraform module, driven by new tag-triggered GitHub Actions workflows (`terraform-provider/v*`, `terraform-aws-source-module/v*`) that sync code to public repos on `copybara/vX.Y.Z` branches. > > Introduces release automation in the provider/module repos: Copybara finalization workflows that open PRs from `copybara/v*`, `tag-on-merge` workflows that create version tags using a `RELEASE_PAT`, and (for the provider) a GoReleaser-based release with GPG-signed checksums plus a Terraform registry manifest; provider `main.go` now uses an ldflags-injected `version` variable. > > Updates `copy.bara.sky` with two new workflows (`terraform-provider`, `terraform-aws-source-module`) and wires new Terraform-managed GitHub Actions secrets/inputs (including new PAT variables) through `deploy/` and the devcontainer to support the public repo automation; ADR index is updated to include newly accepted ADRs. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit d3a131760eadca87088922bf8eca86de2c1be730. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> GitOrigin-RevId: 800dbd7acd6e954106b6a2f1125fc7526c0b2634
1 parent c604891 commit 34aa56e

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Finalize Copybara Sync
2+
3+
on:
4+
push:
5+
branches:
6+
- 'copybara/v*'
7+
8+
concurrency:
9+
group: copybara-sync-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
jobs:
13+
finalize:
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: write
17+
pull-requests: write
18+
19+
steps:
20+
- name: Extract version from branch name
21+
id: version
22+
run: |
23+
VERSION=$(echo "$GITHUB_REF" | sed 's|refs/heads/copybara/||')
24+
echo "version=$VERSION" >> $GITHUB_OUTPUT
25+
26+
- uses: actions/checkout@v6
27+
with:
28+
ref: ${{ github.ref }}
29+
fetch-depth: 0
30+
31+
- name: Extract original commit author
32+
id: author
33+
run: |
34+
AUTHOR_EMAIL=$(git log -1 --format='%ae' --author='^(?!.*actions@github.com)' --perl-regexp 2>/dev/null || git log -1 --format='%ae')
35+
AUTHOR_NAME=$(git log -1 --format='%an' --author='^(?!.*actions@github.com)' --perl-regexp 2>/dev/null || git log -1 --format='%an')
36+
echo "email=$AUTHOR_EMAIL" >> $GITHUB_OUTPUT
37+
echo "name=$AUTHOR_NAME" >> $GITHUB_OUTPUT
38+
39+
if [[ "$AUTHOR_EMAIL" =~ ^([^@]+)@users\.noreply\.github\.com$ ]]; then
40+
GITHUB_USER=$(echo "${BASH_REMATCH[1]}" | sed 's/^[0-9]*+//')
41+
echo "github_user=$GITHUB_USER" >> $GITHUB_OUTPUT
42+
else
43+
echo "github_user=" >> $GITHUB_OUTPUT
44+
fi
45+
46+
- name: Create Pull Request
47+
env:
48+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
VERSION: ${{ steps.version.outputs.version }}
50+
AUTHOR_NAME: ${{ steps.author.outputs.name }}
51+
AUTHOR_EMAIL: ${{ steps.author.outputs.email }}
52+
GITHUB_USER: ${{ steps.author.outputs.github_user }}
53+
run: |
54+
PR_BODY="## Copybara Sync - Release ${VERSION}
55+
56+
This PR was automatically created by Copybara, syncing changes from the [overmindtech/workspace](https://github.com/overmindtech/workspace) monorepo.
57+
58+
**Original author:** ${AUTHOR_NAME} (${AUTHOR_EMAIL})
59+
60+
### What happens when this PR is merged?
61+
62+
1. The \`tag-on-merge\` workflow will automatically create the \`${VERSION}\` tag on main
63+
2. Terraform Registry will detect the tag via webhook and publish the module
64+
65+
### Review Checklist
66+
67+
- [ ] Changes look correct and match the expected monorepo sync
68+
"
69+
70+
PR_URL=$(gh pr create \
71+
--base main \
72+
--head "${{ github.ref_name }}" \
73+
--title "Release ${VERSION}" \
74+
--body "$PR_BODY")
75+
76+
echo "Created PR: $PR_URL"
77+
78+
if [ -n "$GITHUB_USER" ]; then
79+
echo "Requesting review from original author: $GITHUB_USER"
80+
gh pr edit "$PR_URL" --add-reviewer "$GITHUB_USER" || true
81+
fi
82+
83+
echo "Requesting review from Engineering team"
84+
gh pr edit "$PR_URL" --add-reviewer "overmindtech/Engineering" || true

.github/workflows/tag-on-merge.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Tag Release on Merge
2+
3+
on:
4+
pull_request:
5+
types:
6+
- closed
7+
branches:
8+
- main
9+
10+
jobs:
11+
tag-release:
12+
if: github.event.pull_request.merged == true && startsWith(github.event.pull_request.head.ref, 'copybara/v')
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
17+
steps:
18+
- name: Extract version from branch name
19+
id: version
20+
run: |
21+
BRANCH="${{ github.event.pull_request.head.ref }}"
22+
VERSION=$(echo "$BRANCH" | sed 's|copybara/||')
23+
echo "version=$VERSION" >> $GITHUB_OUTPUT
24+
echo "Extracted version: $VERSION"
25+
26+
- uses: actions/checkout@v6
27+
with:
28+
ref: main
29+
fetch-depth: 0
30+
token: ${{ secrets.RELEASE_PAT }}
31+
32+
- name: Configure Git
33+
run: |
34+
git config user.name "GitHub Actions Bot"
35+
git config user.email "actions@github.com"
36+
37+
- name: Create and push tag
38+
env:
39+
VERSION: ${{ steps.version.outputs.version }}
40+
run: |
41+
echo "Creating tag: $VERSION"
42+
git tag "$VERSION"
43+
git push origin "$VERSION"
44+
echo "Successfully pushed tag $VERSION"
45+
46+
- name: Delete copybara branch
47+
env:
48+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
run: |
50+
BRANCH="${{ github.event.pull_request.head.ref }}"
51+
echo "Deleting branch: $BRANCH"
52+
git push origin --delete "$BRANCH" || echo "Branch may have already been deleted"

0 commit comments

Comments
 (0)