Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: '20.x'

- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: '1.14.8'

- name: Install
run: npm ci
- name: Build
Expand Down
41 changes: 23 additions & 18 deletions .github/workflows/npm-publish-beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,24 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'


- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: '1.14.8'

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Run tests
run: npm run test

Expand All @@ -34,10 +39,10 @@ jobs:
run: |
# Get the current version from package.json
CURRENT_VERSION=$(node -p "require('./package.json').version")

# Generate a timestamp for uniqueness
TIMESTAMP=$(date +"%Y%m%d%H%M%S")

# For PR: use PR number in version
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
BETA_VERSION="$CURRENT_VERSION-beta.pr.${{ github.event.pull_request.number }}.$TIMESTAMP"
Expand All @@ -46,13 +51,13 @@ jobs:
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7)
BETA_VERSION="$CURRENT_VERSION-beta.$SHORT_SHA.$TIMESTAMP"
fi

# Set output for use in next step
echo "version=$BETA_VERSION" >> $GITHUB_OUTPUT

# Update package.json with new version
npm version $BETA_VERSION --no-git-tag-version

- name: Publish beta to npm
run: npm publish --tag beta --access public
env:
Expand All @@ -72,12 +77,12 @@ jobs:
}
in_section == 1 { print; }
' CHANGELOG.md)

# Store changelog content in output variable, handling multiline output
echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG_CONTENT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

- name: Create GitHub Pre-release
uses: actions/github-script@v6
with:
Expand All @@ -86,7 +91,7 @@ jobs:
const version = process.env.BETA_VERSION;
const changelog = process.env.CHANGELOG;
const eventType = process.env.GITHUB_EVENT_NAME;

let releaseTitle, releaseTag;
if (eventType === 'pull_request') {
const prNumber = process.env.PR_NUMBER;
Expand All @@ -97,7 +102,7 @@ jobs:
releaseTitle = `Beta Release (${shortSha}): ${version}`;
releaseTag = `beta-${shortSha}`;
}

// Delete existing tag if it exists
try {
await github.rest.git.deleteRef({
Expand All @@ -109,15 +114,15 @@ jobs:
} catch (error) {
console.log(`Tag ${releaseTag} doesn't exist or couldn't be deleted: ${error.message}`);
}

// Try to delete existing release if it exists
try {
const { data: releases } = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 100
});

const existingRelease = releases.find(release => release.tag_name === releaseTag);
if (existingRelease) {
console.log(`Deleting existing release with ID: ${existingRelease.id}`);
Expand All @@ -130,7 +135,7 @@ jobs:
} catch (error) {
console.log(`Error checking/deleting existing release: ${error.message}`);
}

// Create a new release
try {
const { data } = await github.rest.repos.createRelease({
Expand All @@ -145,7 +150,7 @@ jobs:
draft: false,
prerelease: true
});

console.log(`Created pre-release: ${data.html_url}`);
} catch (error) {
console.log(`Error creating release: ${error.message}`);
Expand All @@ -168,7 +173,7 @@ jobs:
const version = process.env.BETA_VERSION;
const packageName = '@space48/cloud-seed';
const installCmd = `npm install ${packageName}@${version}`;

github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
Expand Down
41 changes: 23 additions & 18 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,27 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '20.x'
registry-url: 'https://registry.npmjs.org'


- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: '1.14.8'

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build

- name: Run tests
run: npm run test

- name: Get package version
id: package-version
run: echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
Expand All @@ -34,16 +39,16 @@ jobs:
run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Extract changelog for version
id: extract-changelog
run: |
VERSION="v${{ steps.package-version.outputs.version }}"
echo "Extracting changelog for $VERSION"

# Create a tag for the version
git tag $VERSION

# Extract changelog for the current version
CHANGELOG_CONTENT=$(awk -v ver="$VERSION" '
BEGIN { in_section = 0; }
Expand All @@ -53,20 +58,20 @@ jobs:
}
in_section == 1 { print; }
' CHANGELOG.md)

# Store changelog content in output variable, handling multiline output
echo "changelog<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGELOG_CONTENT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT

- name: Create GitHub Release
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const version = process.env.PACKAGE_VERSION;
const changelog = process.env.CHANGELOG;

const { data } = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
Expand All @@ -76,12 +81,12 @@ jobs:
draft: false,
prerelease: false
});

console.log(`Created release: ${data.html_url}`);
env:
PACKAGE_VERSION: ${{ steps.package-version.outputs.version }}
CHANGELOG: ${{ steps.extract-changelog.outputs.changelog }}

- name: Find related PRs and comment
uses: actions/github-script@v6
with:
Expand All @@ -90,28 +95,28 @@ jobs:
const version = process.env.PACKAGE_VERSION;
const packageName = '@space48/cloud-seed';
const installCmd = `npm install ${packageName}@${version}`;

// Get the commit message to find PR number
const { data: commit } = await github.rest.repos.getCommit({
owner: context.repo.owner,
repo: context.repo.repo,
ref: context.sha
});

// Look for PR references in the commit message (like "Merge pull request #123")
const prMatch = commit.commit.message.match(/Merge pull request #(\d+)/i);

if (prMatch && prMatch[1]) {
const prNumber = parseInt(prMatch[1], 10);

// Comment on the PR
await github.rest.issues.createComment({
issue_number: prNumber,
owner: context.repo.owner,
repo: context.repo.repo,
body: `🚀 New version published: **${version}**\n\nThis version has been published to npm and is now available.\n\nYou can install it with:\n\`\`\`bash\n${installCmd}\n\`\`\``
});

console.log(`Commented on PR #${prNumber} about the new release ${version}`);
} else {
console.log('No PR reference found in the commit message. Skipping comment.');
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [5.2.0](https://github.com/Space48/cloud-seed/compare/v5.1.0...v5.2.0)

### Added

- Google provider bindings are now exported as @space48/cloud-seed/providers/google
- Archive provider bindings are now exported as @space48/cloud-seed/providers/archive

### Changed

- Replaced prebuilt @cdktf/provider-google and @cdktf/provider-archive providers, which were no longer supported, with locally generated bindings
- Google provider upgraded to 7.41.0
- Archive provider upgraded to 2.8.0

### Fixed

- Fixed functions retaining their direct VPC egress configuration after the vpc configuration is removed in runtimeConfig

## [5.1.0](https://github.com/Space48/cloud-seed/compare/v5.0.2...v5.1.0)

### Added
Expand Down
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ export const runtimeConfig: GcpConfig = {

If your function needs access to resources on a VPC network (e.g. a back-office service over an IPSec VPN), you can configure it to route egress traffic through a VPC. All VPC settings are grouped under the `vpc` key in `runtimeConfig`.

> **Note:** VPC resources (connectors, networks, subnets) must already exist in your GCP project. Cloud Seed will configure the function to use them but will not create them. For gen1 functions, only the `connector` option is supported — `network` and `subnet` are ignored. For gen2 functions, if `network` or `subnet` is provided, direct VPC egress is used and the `connector` setting is ignored. Direct VPC egress requires `@cdktf/provider-google` to be built against Terraform Google provider >= 7.x.
> **Note:** VPC resources (connectors, networks, subnets) must already exist in your GCP project. Cloud Seed will configure the function to use them but will not create them. For gen1 functions, only the `connector` option is supported — `network` and `subnet` are ignored. For gen2 functions, if `network` or `subnet` is provided, direct VPC egress is used and the `connector` setting is ignored. Direct VPC egress uses the generated Google provider bindings included with this package.

> **Note:** These options are incompatible with static IP settings. If a function is configured to use a static IP address, it won't be able to access VPN resources.

Expand Down Expand Up @@ -384,7 +384,7 @@ This package can also be called via a JS API.

```typescript
import { build, BaseConfig } from "@space48/cloud-seed";
import GoogleProvider from "@cdktf/provider-google";
import { provider as GoogleProvider, storageBucket } from "@space48/cloud-seed/providers/google";
import { GcsBackend, TerraformStack } from "cdktf";
import { Construct } from "constructs";

Expand All @@ -403,7 +403,7 @@ class CustomStack extends TerraformStack {
/**
* Example infrastructure
*/
new GoogleProvider.StorageBucket(this, "CustomBucket", {
new storageBucket.StorageBucket(this, "CustomBucket", {
name: `my-custom-bucket-${process.env.ENVIRONMENT}`,
location: options.cloud.gcp.region.toUpperCase(),
storageClass: "STANDARD",
Expand All @@ -419,6 +419,16 @@ new CustomStack(app, "CustomStack", config);

app.synth();
```

The generated Google provider bindings are exported from
`@space48/cloud-seed/providers/google`. Consumer applications can use these bindings for
additional infrastructure without running `cdktf provider add`. Cloud Seed currently generates
them from Terraform Google provider `7.41.0`; the Terraform provider is downloaded during the
normal `terraform init` step.

The generated Archive provider bindings are similarly exported from
`@space48/cloud-seed/providers/archive`. They are generated from Terraform Archive provider
`2.8.0`.
# Cloud functions gen 2
It is recommended by google to use the [gen 2](https://cloud.google.com/functions/docs/concepts/version-comparison) functions wherever possible.

Expand Down
8 changes: 6 additions & 2 deletions cdktf.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
{
"language": "typescript",
"app": "node dist/bin/entrypoint.js build --env $ENVIRONMENT",
"terraformProviders": [],
"terraformProviders": [
"hashicorp/google@7.41.0",
"hashicorp/archive@2.8.0"
],
"context": {
"excludeStackIdFromLogicalIds": "true",
"allowSepCharsInLogicalIds": "true"
}
},
"projectId": "aa51f85a-d36c-4b9c-bc2f-8ebf3d963542"
}
Loading
Loading