File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88
99permissions :
1010 contents : write
11+ id-token : write
1112
1213jobs :
1314 install-dependencies :
@@ -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
Original file line number Diff line number Diff line change 1+ .terraform /
2+ * .tfplan
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments