mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
fix: improve dry run handling in Terraform provider publishing script
This commit is contained in:
212
.github/workflows/release.yml
vendored
212
.github/workflows/release.yml
vendored
@@ -1591,7 +1591,6 @@ jobs:
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY || '' }}
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
@@ -1635,216 +1634,9 @@ jobs:
|
||||
if [ -d "Scripts" ]; then cd Scripts && npm install && cd ..; fi
|
||||
|
||||
- name: Generate Terraform provider
|
||||
run: npm run generate-terraform-provider
|
||||
run: npm run publish-terraform-provider -- --version ${{ steps.version.outputs.version }}
|
||||
|
||||
- name: Setup Terraform provider for publishing
|
||||
working-directory: ./Terraform
|
||||
run: |
|
||||
|
||||
# Create .goreleaser.yml
|
||||
cat > .goreleaser.yml << 'EOF'
|
||||
version: 2
|
||||
|
||||
before:
|
||||
hooks:
|
||||
- go mod tidy
|
||||
|
||||
builds:
|
||||
- env:
|
||||
- CGO_ENABLED=0
|
||||
mod_timestamp: '{{ .CommitTimestamp }}'
|
||||
flags:
|
||||
- -trimpath
|
||||
ldflags:
|
||||
- '-s -w -X main.version={{.Version}} -X main.commit={{.Commit}}'
|
||||
goos:
|
||||
- freebsd
|
||||
- windows
|
||||
- linux
|
||||
- darwin
|
||||
goarch:
|
||||
- amd64
|
||||
- '386'
|
||||
- arm
|
||||
- arm64
|
||||
ignore:
|
||||
- goos: darwin
|
||||
goarch: '386'
|
||||
binary: '{{ .ProjectName }}_v{{ .Version }}'
|
||||
|
||||
archives:
|
||||
- format: zip
|
||||
name_template: '{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}'
|
||||
|
||||
checksum:
|
||||
extra_files:
|
||||
- glob: 'terraform-registry-manifest.json'
|
||||
name_template: '{{ .ProjectName }}_{{ .Version }}_manifest.json'
|
||||
name_template: '{{ .ProjectName }}_{{ .Version }}_SHA256SUMS'
|
||||
algorithm: sha256
|
||||
|
||||
signs:
|
||||
- artifacts: checksum
|
||||
args:
|
||||
- "--batch"
|
||||
- "--local-user"
|
||||
- "{{ .Env.GPG_FINGERPRINT | default \"\" }}"
|
||||
- "--output"
|
||||
- "${signature}"
|
||||
- "--detach-sign"
|
||||
- "${artifact}"
|
||||
# Only sign if GPG_FINGERPRINT is available
|
||||
skip: '{{ if .Env.GPG_FINGERPRINT }}false{{ else }}true{{ end }}'
|
||||
|
||||
release:
|
||||
extra_files:
|
||||
- glob: 'terraform-registry-manifest.json'
|
||||
name_template: '{{ .ProjectName }}_{{ .Version }}'
|
||||
|
||||
changelog:
|
||||
use: github
|
||||
sort: asc
|
||||
abbrev: 0
|
||||
EOF
|
||||
|
||||
# Create terraform-registry-manifest.json
|
||||
cat > terraform-registry-manifest.json << 'EOF'
|
||||
{
|
||||
"version": 1,
|
||||
"metadata": {
|
||||
"protocol_versions": ["6.0"]
|
||||
}
|
||||
}
|
||||
EOF
|
||||
|
||||
# Update dependencies
|
||||
go mod tidy
|
||||
|
||||
- name: Validate Go build
|
||||
working-directory: ./Terraform
|
||||
run: |
|
||||
go build -v .
|
||||
|
||||
- name: Run tests
|
||||
working-directory: ./Terraform
|
||||
run: |
|
||||
if ls *_test.go 1> /dev/null 2>&1; then
|
||||
go test -v ./...
|
||||
else
|
||||
echo "No test files found, skipping tests"
|
||||
fi
|
||||
|
||||
- name: Setup Git for terraform provider repo
|
||||
run: |
|
||||
git config --global user.name "github-actions[bot]"
|
||||
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
||||
|
||||
- name: Push to terraform-provider-oneuptime repository
|
||||
env:
|
||||
TERRAFORM_PROVIDER_TOKEN: ${{ secrets.TERRAFORM_PROVIDER_TOKEN }}
|
||||
run: |
|
||||
# Clone the terraform provider repository
|
||||
git clone https://x-access-token:${TERRAFORM_PROVIDER_TOKEN}@github.com/OneUptime/terraform-provider-oneuptime.git terraform-provider-repo
|
||||
|
||||
# Copy generated terraform files to the provider repository
|
||||
cd terraform-provider-repo
|
||||
|
||||
# Clear existing content (except .git)
|
||||
find . -mindepth 1 -name '.git' -prune -o -type f -exec rm -f {} +
|
||||
find . -mindepth 1 -name '.git' -prune -o -type d -exec rm -rf {} +
|
||||
|
||||
# Copy terraform provider files
|
||||
cp -r ../Terraform/* .
|
||||
|
||||
# Ensure we have the required files
|
||||
if [ ! -f "go.mod" ] || [ ! -f "main.go" ] || [ ! -f "provider.go" ]; then
|
||||
echo "Error: Required terraform provider files not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Add all files
|
||||
git add .
|
||||
|
||||
# Check if there are changes to commit
|
||||
if git diff --staged --quiet; then
|
||||
echo "No changes to commit for terraform provider"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Commit changes
|
||||
git commit -m "Release terraform provider v${{ steps.version.outputs.version }}
|
||||
|
||||
Auto-generated from OneUptime main repository
|
||||
Build: ${{needs.generate-build-number.outputs.build_number}}
|
||||
Commit: ${{ github.sha }}
|
||||
"
|
||||
|
||||
# Create and push tag
|
||||
git tag "v${{ steps.version.outputs.version }}"
|
||||
|
||||
# Push changes and tag
|
||||
git push origin main
|
||||
git push origin "v${{ steps.version.outputs.version }}"
|
||||
|
||||
echo "Successfully pushed terraform provider v${{ steps.version.outputs.version }} to OneUptime/terraform-provider-oneuptime"
|
||||
|
||||
- name: Create terraform provider release
|
||||
env:
|
||||
TERRAFORM_PROVIDER_TOKEN: ${{ secrets.TERRAFORM_PROVIDER_TOKEN }}
|
||||
run: |
|
||||
# Use GitHub CLI to create release in the terraform provider repository
|
||||
cd terraform-provider-repo
|
||||
|
||||
# Create release notes
|
||||
cat > release-notes.md << EOF
|
||||
# OneUptime Terraform Provider v${{ steps.version.outputs.version }}
|
||||
|
||||
## What's Changed
|
||||
|
||||
This release includes the latest OneUptime Terraform provider generated from the OneUptime API specification.
|
||||
|
||||
### Features
|
||||
- Full support for OneUptime resources and data sources
|
||||
- Auto-generated from OpenAPI specification
|
||||
- Supports all OneUptime monitoring and incident management features
|
||||
|
||||
### Installation
|
||||
|
||||
\`\`\`hcl
|
||||
terraform {
|
||||
required_providers {
|
||||
oneuptime = {
|
||||
source = "oneuptime/oneuptime"
|
||||
version = "~> ${{ steps.version.outputs.version }}"
|
||||
}
|
||||
}
|
||||
}
|
||||
\`\`\`
|
||||
|
||||
### Build Information
|
||||
- **Build Number**: ${{needs.generate-build-number.outputs.build_number}}
|
||||
- **Source Commit**: ${{ github.sha }}
|
||||
- **Generated**: $(date -u)
|
||||
|
||||
For detailed documentation and examples, visit: https://registry.terraform.io/providers/oneuptime/oneuptime/latest/docs
|
||||
EOF
|
||||
|
||||
# Create GitHub release
|
||||
gh release create "v${{ steps.version.outputs.version }}" \
|
||||
--title "OneUptime Terraform Provider v${{ steps.version.outputs.version }}" \
|
||||
--notes-file release-notes.md \
|
||||
--repo OneUptime/terraform-provider-oneuptime
|
||||
|
||||
- name: Post-release summary
|
||||
run: |
|
||||
echo "## 🚀 Terraform Provider Release Summary" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "**Version:** ${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
|
||||
echo "**Provider Name:** oneuptime" >> $GITHUB_STEP_SUMMARY
|
||||
echo "**GitHub Release:** https://github.com/OneUptime/terraform-provider-oneuptime/releases/tag/v${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
|
||||
echo "**Terraform Registry:** https://registry.terraform.io/providers/oneuptime/oneuptime/${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY
|
||||
echo "" >> $GITHUB_STEP_SUMMARY
|
||||
echo "The provider will be available on the Terraform Registry within a few minutes." >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -264,17 +264,16 @@ create_github_release() {
|
||||
|
||||
cd "$TERRAFORM_DIR"
|
||||
|
||||
if [[ "$DRY_RUN" == true ]]; then
|
||||
print_warning "DRY RUN: Would create GitHub release v$VERSION"
|
||||
return
|
||||
fi
|
||||
|
||||
# Authenticate with GitHub using token
|
||||
if [[ -z "$GITHUB_TOKEN" ]]; then
|
||||
print_error "GITHUB_TOKEN environment variable is required for GitHub authentication"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$DRY_RUN" == true ]]; then
|
||||
print_warning "DRY RUN: Creating draft release v$VERSION (will not be published)"
|
||||
fi
|
||||
|
||||
# Set up authentication for git and GitHub API
|
||||
export GH_TOKEN="$GITHUB_TOKEN"
|
||||
git config --global credential.helper store
|
||||
@@ -330,7 +329,11 @@ For detailed documentation and examples, visit: https://registry.terraform.io/pr
|
||||
EOF
|
||||
|
||||
# Create the release
|
||||
print_status "Creating GitHub release v$VERSION..."
|
||||
if [[ "$DRY_RUN" == true ]]; then
|
||||
print_status "Creating draft release v$VERSION for dry run..."
|
||||
else
|
||||
print_status "Creating GitHub release v$VERSION..."
|
||||
fi
|
||||
|
||||
if [[ "$use_gh_cli" == true ]]; then
|
||||
# Use GitHub CLI if available
|
||||
@@ -338,7 +341,12 @@ EOF
|
||||
--title "OneUptime Terraform Provider v$VERSION" \
|
||||
--notes-file "$release_notes_file" \
|
||||
--draft; then
|
||||
print_success "GitHub release created successfully"
|
||||
if [[ "$DRY_RUN" == true ]]; then
|
||||
print_success "Draft release created successfully for dry run"
|
||||
print_status "Note: This is a draft release. You can review it at: https://github.com/$GITHUB_ORG/$PROVIDER_REPO/releases/tag/v$VERSION"
|
||||
else
|
||||
print_success "GitHub release created successfully"
|
||||
fi
|
||||
else
|
||||
print_error "Failed to create GitHub release"
|
||||
exit 1
|
||||
@@ -359,7 +367,12 @@ EOF
|
||||
}")
|
||||
|
||||
if echo "$response" | jq -e '.id' > /dev/null; then
|
||||
print_success "GitHub release created successfully via API"
|
||||
if [[ "$DRY_RUN" == true ]]; then
|
||||
print_success "Draft release created successfully for dry run via API"
|
||||
print_status "Note: This is a draft release. You can review it at: https://github.com/$GITHUB_ORG/$PROVIDER_REPO/releases/tag/v$VERSION"
|
||||
else
|
||||
print_success "GitHub release created successfully via API"
|
||||
fi
|
||||
else
|
||||
print_error "Failed to create GitHub release via API"
|
||||
echo "Response: $response"
|
||||
@@ -376,7 +389,8 @@ publish_to_registry() {
|
||||
print_step "Publishing to Terraform Registry..."
|
||||
|
||||
if [[ "$DRY_RUN" == true ]]; then
|
||||
print_warning "DRY RUN: Would publish to Terraform Registry"
|
||||
print_warning "DRY RUN: Skipping Terraform Registry publishing"
|
||||
print_status "In a real run, the Terraform Registry would automatically detect the published release"
|
||||
return
|
||||
fi
|
||||
|
||||
@@ -421,7 +435,17 @@ show_summary() {
|
||||
echo ""
|
||||
|
||||
if [[ "$DRY_RUN" == true ]]; then
|
||||
print_warning "This was a DRY RUN - no actual publishing occurred"
|
||||
print_warning "This was a DRY RUN with the following actions taken:"
|
||||
echo "✓ Generated Terraform provider"
|
||||
echo "✓ Ran tests (if not skipped)"
|
||||
echo "✓ Created draft GitHub release v$VERSION"
|
||||
echo "✗ Skipped Terraform Registry publishing"
|
||||
echo ""
|
||||
print_status "Next steps for a real release:"
|
||||
echo "1. Review the draft release: https://github.com/$GITHUB_ORG/$PROVIDER_REPO/releases/tag/v$VERSION"
|
||||
echo "2. If satisfied, publish the release (remove draft status)"
|
||||
echo "3. Or run the script again without --dry-run flag"
|
||||
echo "4. Monitor Terraform Registry for automatic indexing"
|
||||
else
|
||||
print_success "Terraform provider published successfully!"
|
||||
echo ""
|
||||
|
||||
@@ -73,8 +73,7 @@
|
||||
"generate-postgres-migration": "export $(grep -v '^#' config.env | xargs) && node --require ts-node/register ./node_modules/typeorm/cli.js migration:generate ./Common/Server/Infrastructure/Postgres/SchemaMigrations/MigrationName -d ./Common/Server/Infrastructure/Postgres/LocalMigrationGenerationDataSource.ts",
|
||||
"generate-openapi-spec": "export $(grep -v '^#' config.env | xargs) && node --require ts-node/register ./Scripts/OpenAPI/GenerateSpec.ts ./openapi.json",
|
||||
"generate-terraform-provider": "export $(grep -v '^#' config.env | xargs) && node --require ts-node/register ./Scripts/TerraformProvider/GenerateProvider.ts",
|
||||
"publish-terraform-provider": "bash ./scripts/publish-terraform-provider.sh",
|
||||
"publish-terraform-provider-dry-run": "bash ./scripts/publish-terraform-provider.sh --dry-run"
|
||||
"publish-terraform-provider": "bash ./scripts/publish-terraform-provider.sh"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
Reference in New Issue
Block a user