Skip to content

Commit 35bace0

Browse files
committed
Add example e2e workflow and provider build artifact workflow
1 parent a850fee commit 35bace0

2 files changed

Lines changed: 216 additions & 0 deletions

File tree

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# Example workflow for spicehq/cloud to consume the terraform provider artifact
2+
# Copy and adapt this workflow to your e2e test needs
3+
#
4+
# This workflow demonstrates how to:
5+
# 1. Download the pre-built provider from terraform-provider-spiceai (internal repo)
6+
# 2. Configure Terraform to use it via dev overrides
7+
# 3. Run e2e tests with the provider
8+
#
9+
# IMPORTANT: Since terraform-provider-spiceai is an internal repo, you need a PAT
10+
# or GitHub App token with `actions:read` permission on the source repo.
11+
# The default GITHUB_TOKEN does NOT work for cross-repo artifact access.
12+
13+
name: E2E Tests
14+
15+
on:
16+
pull_request:
17+
push:
18+
branches:
19+
- main
20+
21+
permissions:
22+
contents: read
23+
24+
jobs:
25+
e2e:
26+
name: E2E Tests
27+
runs-on: ubuntu-latest
28+
timeout-minutes: 30
29+
steps:
30+
- uses: actions/checkout@v4
31+
32+
# Download the provider artifact from terraform-provider-spiceai repo
33+
#
34+
# Required secret: GH_PAT
35+
# Create a Personal Access Token (classic) or Fine-grained PAT with:
36+
# - actions:read permission on spicehq/terraform-provider-spiceai
37+
# Or use a GitHub App installation token with Actions read permission
38+
#
39+
# To create the secret:
40+
# 1. Go to spicehq/cloud -> Settings -> Secrets and variables -> Actions
41+
# 2. Create a new secret named GH_PAT with your token
42+
- name: Download Terraform Provider
43+
uses: dawidd6/action-download-artifact@v6
44+
with:
45+
github_token: ${{ secrets.GH_PAT }}
46+
repo: spicehq/terraform-provider-spiceai
47+
workflow: build-artifact.yml
48+
branch: main
49+
name: terraform-provider-spiceai_linux_amd64
50+
path: .terraform-provider
51+
52+
# Alternative: Download using GitHub CLI
53+
# Uncomment this block and comment out the above step if you prefer gh cli
54+
# - name: Download Terraform Provider (gh cli)
55+
# env:
56+
# GH_TOKEN: ${{ secrets.GH_PAT }}
57+
# run: |
58+
# mkdir -p .terraform-provider
59+
#
60+
# # Get the latest successful workflow run
61+
# RUN_ID=$(gh run list \
62+
# --repo spicehq/terraform-provider-spiceai \
63+
# --workflow build-artifact.yml \
64+
# --branch main \
65+
# --status success \
66+
# --limit 1 \
67+
# --json databaseId \
68+
# --jq '.[0].databaseId')
69+
#
70+
# # Download the artifact
71+
# gh run download "$RUN_ID" \
72+
# --repo spicehq/terraform-provider-spiceai \
73+
# --name terraform-provider-spiceai_linux_amd64 \
74+
# --dir .terraform-provider
75+
76+
- name: Setup Terraform Provider
77+
run: |
78+
chmod +x .terraform-provider/terraform-provider-spiceai_linux_amd64
79+
80+
# Rename binary to match what Terraform expects
81+
mv .terraform-provider/terraform-provider-spiceai_linux_amd64 \
82+
.terraform-provider/terraform-provider-spiceai
83+
84+
# Create Terraform CLI config with dev override
85+
mkdir -p ~/.terraform.d
86+
cat > ~/.terraform.d/terraformrc << EOF
87+
provider_installation {
88+
dev_overrides {
89+
"spiceai/spiceai" = "${{ github.workspace }}/.terraform-provider"
90+
}
91+
direct {}
92+
}
93+
EOF
94+
95+
- name: Setup Terraform
96+
uses: hashicorp/setup-terraform@v3
97+
with:
98+
terraform_wrapper: false
99+
100+
# Your e2e test steps go here
101+
- name: Run E2E Tests
102+
env:
103+
SPICEAI_CLIENT_ID: ${{ secrets.SPICEAI_CLIENT_ID }}
104+
SPICEAI_CLIENT_SECRET: ${{ secrets.SPICEAI_CLIENT_SECRET }}
105+
TF_CLI_CONFIG_FILE: ~/.terraform.d/terraformrc
106+
run: |
107+
cd path/to/your/terraform/configs
108+
109+
# Note: With dev overrides, Terraform will warn that it's using
110+
# a locally-installed provider. This is expected behavior.
111+
terraform plan
112+
terraform apply -auto-approve
113+
114+
# Run your e2e test assertions here
115+
116+
# Cleanup
117+
terraform destroy -auto-approve
118+
119+
# =============================================================================
120+
# Setup Instructions
121+
# =============================================================================
122+
#
123+
# 1. Create a PAT (Personal Access Token):
124+
# - Go to GitHub Settings -> Developer settings -> Personal access tokens
125+
# - For Fine-grained token (recommended):
126+
# - Resource owner: spicehq
127+
# - Repository access: Select "spicehq/terraform-provider-spiceai"
128+
# - Permissions: Actions (read)
129+
# - For Classic token:
130+
# - Select scope: repo (for internal repos)
131+
#
132+
# 2. Add the PAT as a secret in spicehq/cloud:
133+
# - Go to spicehq/cloud -> Settings -> Secrets and variables -> Actions
134+
# - New repository secret: GH_PAT = <your-token>
135+
#
136+
# 3. Also add Spice.ai credentials as secrets:
137+
# - SPICEAI_CLIENT_ID
138+
# - SPICEAI_CLIENT_SECRET
139+
#
140+
# =============================================================================
141+
# Notes
142+
# =============================================================================
143+
#
144+
# - Artifacts are retained for 90 days by default
145+
# - For macOS runners, use macos-latest and download darwin_arm64 or darwin_amd64
146+
# - The provider is built on every merge to main in terraform-provider-spiceai
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Build and upload provider artifact on merge to trunk
2+
name: Build Artifact
3+
4+
on:
5+
pull_request:
6+
7+
push:
8+
branches:
9+
- trunk
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
build:
16+
name: Build Provider
17+
runs-on: ubuntu-latest
18+
timeout-minutes: 10
19+
strategy:
20+
matrix:
21+
include:
22+
- goos: linux
23+
goarch: amd64
24+
- goos: linux
25+
goarch: arm64
26+
- goos: darwin
27+
goarch: amd64
28+
- goos: darwin
29+
goarch: arm64
30+
steps:
31+
- uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
32+
- uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
33+
with:
34+
go-version-file: 'go.mod'
35+
cache: true
36+
37+
- name: Build provider
38+
env:
39+
GOOS: ${{ matrix.goos }}
40+
GOARCH: ${{ matrix.goarch }}
41+
CGO_ENABLED: '0'
42+
run: |
43+
go build -trimpath -ldflags="-s -w" -o terraform-provider-spiceai_${{ matrix.goos }}_${{ matrix.goarch }} .
44+
45+
- name: Upload artifact
46+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
47+
with:
48+
name: terraform-provider-spiceai_${{ matrix.goos }}_${{ matrix.goarch }}
49+
path: terraform-provider-spiceai_${{ matrix.goos }}_${{ matrix.goarch }}
50+
retention-days: 90
51+
52+
# Combine all platform artifacts into a single artifact for convenience
53+
combine:
54+
name: Combine Artifacts
55+
needs: build
56+
runs-on: ubuntu-latest
57+
steps:
58+
- name: Download all artifacts
59+
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
60+
with:
61+
path: artifacts
62+
pattern: terraform-provider-spiceai_*
63+
merge-multiple: true
64+
65+
- name: Upload combined artifact
66+
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
67+
with:
68+
name: terraform-provider-spiceai
69+
path: artifacts/
70+
retention-days: 90

0 commit comments

Comments
 (0)