Skip to content

Commit 3928772

Browse files
committed
feat: add upload to s3
1 parent 930da7d commit 3928772

6 files changed

Lines changed: 152 additions & 2 deletions

File tree

.github/workflows/build.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ on:
88

99
permissions:
1010
contents: write
11+
id-token: write
1112

1213
jobs:
1314
install-dependencies:
@@ -103,7 +104,7 @@ jobs:
103104

104105
publish:
105106
name: Publish to npm
106-
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
107+
# if: github.event_name == 'push' && github.ref == 'refs/heads/main'
107108
needs: [install-dependencies, check-prettier, run-cypress, check-types]
108109
runs-on: ubuntu-latest
109110
steps:
@@ -123,7 +124,24 @@ jobs:
123124
- name: Build the package
124125
run: npm run build
125126
- name: Run semantic release bot
126-
run: npx semantic-release
127+
run: npx semantic-release --dry-run
127128
env:
128129
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
129130
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
131+
- name: Configure AWS credentials
132+
uses: aws-actions/configure-aws-credentials@v4
133+
with:
134+
role-to-assume: arn:aws:iam::457031429343:role/github-actions-browser-sdk-role
135+
aws-region: us-east-1
136+
- name: Upload to S3 with versioning
137+
run: |
138+
# Create version directory based on package version
139+
VERSION=$(node -p "require('./package.json').version")
140+
# Upload to versioned path
141+
aws s3 cp static/cdn.js s3://tbx-assets/browser-sdk/$VERSION/cdn.js --acl public-read
142+
# Create a redirect object for "latest" that points to the versioned file
143+
aws s3api put-object \
144+
--bucket tbx-assets \
145+
--key browser-sdk/latest/cdn.js \
146+
--website-redirect-location /browser-sdk/$VERSION/cdn.js \
147+
--acl public-read

terraform/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.terraform/
2+
*.tfplan

terraform/.terraform.lock.hcl

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

terraform/main.tf

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
provider "aws" {
2+
alias = "testbox-root"
3+
region = "us-east-1"
4+
default_tags {
5+
tags = {
6+
terraform = "true"
7+
}
8+
}
9+
}
10+
11+
terraform {
12+
backend "s3" {
13+
bucket = "tbx-terraform"
14+
key = "browser-sdk.tfstate"
15+
region = "us-west-2"
16+
}
17+
}
18+
19+
resource "aws_iam_role" "github_actions_role" {
20+
name = "github-actions-${var.repo_name}-role"
21+
22+
assume_role_policy = jsonencode({
23+
Version = "2012-10-17"
24+
Statement = [
25+
{
26+
Action = "sts:AssumeRoleWithWebIdentity"
27+
Effect = "Allow"
28+
Principal = {
29+
Federated = "arn:aws:iam::${var.aws_account_id}:oidc-provider/token.actions.githubusercontent.com"
30+
}
31+
Condition = {
32+
StringEquals = {
33+
"token.actions.githubusercontent.com:aud" = "sts.amazonaws.com",
34+
"token.actions.githubusercontent.com:sub" = "repo:${var.github_org}/${var.repo_name}:ref:refs/heads/main"
35+
}
36+
}
37+
}
38+
]
39+
})
40+
}
41+
42+
resource "aws_iam_policy" "s3_deploy_policy" {
43+
name = "s3-deploy-${var.repo_name}-policy"
44+
description = "Policy to allow uploading to specific S3 bucket paths"
45+
46+
policy = jsonencode({
47+
Version = "2012-10-17"
48+
Statement = [
49+
{
50+
Action = [
51+
"s3:PutObject",
52+
"s3:GetObject",
53+
"s3:ListBucket"
54+
]
55+
Effect = "Allow"
56+
Resource = [
57+
"arn:aws:s3:::${var.s3_bucket_name}",
58+
"arn:aws:s3:::${var.s3_bucket_name}/*"
59+
]
60+
}
61+
]
62+
})
63+
}
64+
65+
resource "aws_iam_role_policy_attachment" "s3_deploy_attachment" {
66+
role = aws_iam_role.github_actions_role.name
67+
policy_arn = aws_iam_policy.s3_deploy_policy.arn
68+
}

terraform/outputs.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
output "github_actions_role_arn" {
2+
description = "ARN of the IAM role for GitHub Actions"
3+
value = aws_iam_role.github_actions_role.arn
4+
}
5+
6+
output "s3_deploy_policy_arn" {
7+
description = "ARN of the S3 deployment policy"
8+
value = aws_iam_policy.s3_deploy_policy.arn
9+
}

terraform/variables.tf

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
variable "aws_region" {
2+
description = "AWS region where resources will be created"
3+
type = string
4+
default = "us-east-1"
5+
}
6+
7+
variable "aws_account_id" {
8+
description = "AWS account ID"
9+
type = string
10+
default = "457031429343"
11+
}
12+
13+
variable "github_org" {
14+
description = "GitHub organization name"
15+
type = string
16+
default = "TestBoxLab"
17+
}
18+
19+
variable "repo_name" {
20+
description = "GitHub repository name"
21+
type = string
22+
default = "browser-sdk"
23+
}
24+
25+
variable "s3_bucket_name" {
26+
description = "S3 bucket name where files will be uploaded"
27+
type = string
28+
default = "tbx-assets"
29+
}

0 commit comments

Comments
 (0)