Repository navigation
167 lines (159 loc) · 5.93 KB
/
Copy pathgo-lambda-release.yml
File metadata and controls
167 lines (159 loc) · 5.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
name: Go Lambda Release
on:
workflow_call:
inputs:
go_version:
description: Go version used to build the Lambda binary.
required: false
type: string
default: "1.23"
main_package:
description: Path to the Go main package to build (e.g. ./cmd/authorizer).
required: false
type: string
default: "."
goarch:
description: Target architecture for the Lambda binary (arm64 or amd64).
required: false
type: string
default: "arm64"
artifact_name:
description: File name of the generated zip artifact.
required: false
type: string
default: "bootstrap.zip"
version:
description: Release version used in the S3 key (e.g. v1.2.3). Defaults to the pushed git tag.
required: false
type: string
default: ""
s3_bucket:
description: Target S3 bucket for the artifact.
required: true
type: string
s3_key_prefix:
description: Key prefix under the bucket. Final key is <prefix>/<version>/<artifact_name>.
required: true
type: string
aws_region:
description: AWS region of the target S3 bucket.
required: false
type: string
default: "us-east-2"
dry_run:
description: Build and resolve the target key without uploading to S3.
required: false
type: boolean
default: false
secrets:
AWS_ROLE_ARN:
description: IAM role ARN to assume via OIDC for the S3 upload.
required: true
outputs:
version:
description: Resolved release version.
value: ${{ jobs.release.outputs.version }}
s3_key:
description: Full S3 key of the uploaded artifact.
value: ${{ jobs.release.outputs.s3_key }}
s3_version_id:
description: S3 object version id of the uploaded artifact (empty on dry run).
value: ${{ jobs.release.outputs.s3_version_id }}
binary_sha256:
description: SHA-256 checksum of the built bootstrap binary.
value: ${{ jobs.release.outputs.binary_sha256 }}
# Least privilege by default; the release job escalates for AWS OIDC.
permissions:
contents: read
jobs:
release:
runs-on: ${{ vars.GENERAL_RUNNERS || 'blacksmith-4vcpu-ubuntu-2404' }}
permissions:
id-token: write # AWS OIDC to assume the upload role
contents: read
outputs:
version: ${{ steps.resolve.outputs.version }}
s3_key: ${{ steps.resolve.outputs.s3_key }}
s3_version_id: ${{ steps.upload.outputs.version_id }}
binary_sha256: ${{ steps.build.outputs.binary-sha256 }}
steps:
# ----------------- Checkout & Build -----------------
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
with:
persist-credentials: false
- name: Build Go Lambda artifact
id: build
uses: LerianStudio/github-actions-shared-workflows/src/build/build-go-lambda@develop # TODO: pin to @v1 once released
with:
go-version: ${{ inputs.go_version }}
main-package: ${{ inputs.main_package }}
goarch: ${{ inputs.goarch }}
artifact-name: ${{ inputs.artifact_name }}
# ----------------- Resolve Target Key -----------------
- name: Resolve version and S3 key
id: resolve
shell: bash
env:
INPUT_VERSION: ${{ inputs.version }}
REF_NAME: ${{ github.ref_name }}
REF_TYPE: ${{ github.ref_type }}
S3_KEY_PREFIX: ${{ inputs.s3_key_prefix }}
ARTIFACT_NAME: ${{ inputs.artifact_name }}
run: |
set -euo pipefail
VERSION="$INPUT_VERSION"
if [ -z "$VERSION" ]; then
if [ "$REF_TYPE" = "tag" ]; then
VERSION="$REF_NAME"
else
echo "::error::No version provided and ref is not a tag ($REF_NAME). Pass inputs.version explicitly."
exit 1
fi
fi
PREFIX="${S3_KEY_PREFIX%/}"
S3_KEY="${PREFIX}/${VERSION}/${ARTIFACT_NAME}"
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
echo "s3_key=$S3_KEY" >> "$GITHUB_OUTPUT"
# ----------------- Dry Run -----------------
- name: Dry run summary
if: ${{ inputs.dry_run }}
shell: bash
env:
ARTIFACT_PATH: ${{ steps.build.outputs.artifact-path }}
BINARY_SHA256: ${{ steps.build.outputs.binary-sha256 }}
S3_BUCKET: ${{ inputs.s3_bucket }}
S3_KEY: ${{ steps.resolve.outputs.s3_key }}
AWS_REGION: ${{ inputs.aws_region }}
run: |
echo "::notice::DRY RUN — artifact will not be uploaded"
echo " artifact : $ARTIFACT_PATH"
echo " sha256 : $BINARY_SHA256"
echo " bucket : $S3_BUCKET"
echo " key : $S3_KEY"
echo " region : $AWS_REGION"
# ----------------- Upload to S3 -----------------
- name: Configure AWS credentials
if: ${{ !inputs.dry_run }}
uses: aws-actions/configure-aws-credentials@e7f100cf4c008499ea8adda475de1042d6975c7b # v6.2.0
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ inputs.aws_region }}
- name: Upload artifact to S3
id: upload
if: ${{ !inputs.dry_run }}
shell: bash
env:
ARTIFACT_PATH: ${{ steps.build.outputs.artifact-path }}
S3_BUCKET: ${{ inputs.s3_bucket }}
S3_KEY: ${{ steps.resolve.outputs.s3_key }}
run: |
set -euo pipefail
VERSION_ID=$(aws s3api put-object \
--bucket "$S3_BUCKET" \
--key "$S3_KEY" \
--body "$ARTIFACT_PATH" \
--content-type application/zip \
--query VersionId --output text)
echo "version_id=$VERSION_ID" >> "$GITHUB_OUTPUT"
echo "::notice::Uploaded s3://$S3_BUCKET/$S3_KEY (versionId=$VERSION_ID)"