Skip to content

Commit 335800b

Browse files
authored
Merge pull request #208 from luke-h1/@luke-h1/feat/swift
2 parents 03844f2 + f0e874a commit 335800b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+1143
-2585
lines changed

.bun-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.2.5
1+
1.3.2

.changeset/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Changesets
2+
3+
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
4+
with multi-package repos, or single-package repos to help you version and publish your code. You can
5+
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
6+
7+
We have a quick list of common questions to get you started engaging with this project in
8+
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
9+
10+
## Usage
11+
12+
To add a changeset, run:
13+
14+
```bash
15+
bun run changeset
16+
```
17+
18+
To version the package based on changesets, run:
19+
20+
```bash
21+
bun run changeset:version
22+
```
23+
24+
To check the status of changesets, run:
25+
26+
```bash
27+
bun run changeset:status
28+
```
29+

.changeset/config.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"$schema": "https://unpkg.com/@changesets/[email protected]/schema.json",
3+
"changelog": "@changesets/cli/changelog",
4+
"commit": false,
5+
"fixed": [],
6+
"linked": [],
7+
"access": "restricted",
8+
"baseBranch": "main",
9+
"updateInternalDependencies": "patch",
10+
"ignore": [],
11+
"privatePackages": {
12+
"version": true,
13+
"tag": false
14+
}
15+
}
16+

.github/actions/deploy/action.yml

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ inputs:
1313
runs:
1414
using: composite
1515
steps:
16-
- name: Validate environment
17-
shell: bash
18-
run: if [ "${{ inputs.environment }}" != "staging" ] && [ "${{ inputs.environment }}" != "live" ]; then echo "Invalid environment"; exit 1; fi
19-
2016
- name: Setup Terraform
2117
uses: hashicorp/setup-terraform@v3
2218
with:
@@ -56,26 +52,41 @@ runs:
5652
working-directory: terraform
5753
run: terraform validate
5854

59-
- name: Setup version information
55+
- name: Build functions for Lambda
6056
shell: bash
61-
env:
62-
GITHUB_EVENT_NAME: ${{ github.event_name }}
63-
GITHUB_REF_NAME: ${{ github.ref_name }}
6457
run: |
65-
chmod +x scripts/version.sh
66-
./scripts/version.sh info
58+
docker run --rm \
59+
--platform linux/amd64 \
60+
-v "${{ github.workspace }}:/workspace" \
61+
-w /workspace \
62+
swift:6.1-amazonlinux2 \
63+
bash -c "swift build -c release --static-swift-stdlib && \
64+
cp .build/release/lambda .build/release/bootstrap && \
65+
chmod 755 .build/release/bootstrap && \
66+
mkdir -p .build/release/authorizer-package && \
67+
cp .build/release/authorizer .build/release/authorizer-package/bootstrap && \
68+
chmod 755 .build/release/authorizer-package/bootstrap"
69+
sudo chown -R $(id -u):$(id -g) .build
6770
68-
- name: Build .NET Lambda functions
71+
- name: Get version
72+
id: version
6973
shell: bash
7074
run: |
71-
chmod +x scripts/build.sh
72-
./scripts/build.sh
75+
# Use VERSION env var if set (for pre-releases), otherwise read from package.json
76+
if [ -n "$VERSION" ]; then
77+
echo "Using provided version: $VERSION"
78+
echo "APP_VERSION=$VERSION" >> $GITHUB_ENV
79+
else
80+
PKG_VERSION=$(jq -r .version package.json)
81+
echo "Using package.json version: $PKG_VERSION"
82+
echo "APP_VERSION=$PKG_VERSION" >> $GITHUB_ENV
83+
fi
7384
7485
- name: Terraform plan
7586
id: plan
7687
shell: bash
7788
working-directory: terraform
78-
run: terraform plan -no-color -out=tfplan -var="app_version=$VERSION" -var="git_sha=$GIT_SHA"
89+
run: terraform plan -no-color -out=tfplan -var="app_version=${{ env.APP_VERSION }}" -var="git_sha=$GIT_SHA"
7990

8091
- name: Terraform apply
8192
shell: bash

.github/actions/install/action.yml

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,18 @@ description: Install dependencies
33
runs:
44
using: composite
55
steps:
6-
- name: Install moreutils
7-
run: sudo apt install moreutils
8-
shell: bash
9-
10-
# https://github.com/actions/virtual-environments/issues/1187
11-
- name: tune linux network
12-
run: sudo ethtool -K eth0 tx off rx off
13-
shell: bash
14-
156
- name: Ensure branch is rebased with main
167
run: git stash && git pull --rebase
178
shell: bash
189

19-
- name: Setup .NET
20-
uses: actions/setup-dotnet@v4
10+
- name: Setup Swift
11+
uses: swift-actions/setup-swift@v3
2112
with:
22-
dotnet-version: "8.0.x"
23-
24-
- name: Restore .NET dependencies for main lambda
25-
shell: bash
26-
working-directory: apps/lho-lambda/src
27-
run: dotnet restore
28-
29-
- name: Restore .NET dependencies for authorizer
30-
shell: bash
31-
working-directory: apps/lho-authorizer/src
32-
run: dotnet restore
13+
swift-version: "6.1.0"
3314

34-
# https://github.com/actions/virtual-environments/issues/1187
35-
- name: tune linux network
36-
run: sudo ethtool -K eth0 tx off rx off
15+
- name: Resolve Swift dependencies
3716
shell: bash
17+
run: swift package resolve
3818

3919
- name: 🥟 Setup Bun
4020
uses: oven-sh/setup-bun@v2
Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
name: Install
1+
name: Validate
22
description: Validate
33
runs:
44
using: composite
55
steps:
6-
- name: Build main lambda
6+
- name: Run SwiftLint
77
shell: bash
8-
working-directory: apps/lho-lambda
9-
run: dotnet build --configuration Release --no-restore
8+
run: swiftlint
109

11-
- name: Build authorizer lambda
10+
- name: Build functions
1211
shell: bash
13-
working-directory: apps/lho-authorizer
14-
run: dotnet build --configuration Release --no-restore
12+
run: swift build -c release
Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
name: Build pre-release version
1+
name: Deploy Staging (Pre-release)
2+
23
on:
34
workflow_dispatch:
4-
pull_request:
5-
types: [opened, synchronize, edited, reopened]
5+
66
concurrency:
77
group: ${{ github.workflow }}-${{ github.ref }}
88
cancel-in-progress: true
9+
910
env:
1011
TF_VAR_env: staging
1112
TF_VAR_env_vars: ${{ secrets.LIVE_ENV_VARS }}
@@ -17,62 +18,51 @@ env:
1718
TF_VAR_certificate_chain: ${{ secrets.STAGING_CERTIFICATE_CHAIN }}
1819
TF_VAR_deployed_by: ${{ github.actor }}
1920
TF_VAR_git_sha: ${{ github.sha }}
20-
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
21-
TURBO_TEAM: luke-h1-project
2221
TF_VAR_api_key: ${{ secrets.STAGING_API_KEY }}
23-
TF_VAR_discord_webhook_url: ${{ secrets.DISCORD_ALERTS_WEBHOOK_URL}}
22+
TF_VAR_discord_webhook_url: ${{ secrets.DISCORD_ALERTS_WEBHOOK_URL }}
2423

2524
permissions: write-all
2625

2726
jobs:
2827
deploy:
29-
name: Deploy to staging
28+
name: Deploy to Staging
3029
runs-on: ubuntu-latest
31-
timeout-minutes: 10
30+
timeout-minutes: 15
3231
steps:
3332
- name: Checkout repository
3433
uses: actions/checkout@v4
3534
with:
3635
fetch-depth: 0
37-
ref: ${{ github.head_ref }}
38-
39-
- name: Ensure rebased with main
40-
run: ./scripts/ensure-rebased.sh
41-
42-
- name: Install
43-
uses: ./.github/actions/install
4436

45-
- name: Validate
46-
uses: ./.github/actions/validate
47-
48-
- name: Changelogs
49-
uses: ./.github/actions/changelog
37+
- name: Setup Bun
38+
uses: oven-sh/setup-bun@v2
5039
with:
51-
prerelease: true
52-
publish: false
40+
bun-version-file: ".bun-version"
41+
42+
- name: Install dependencies
43+
run: bun install --frozen-lockfile
5344

54-
- name: fetch latest commits
55-
run: git fetch && git pull
45+
- name: Get pre-release version
46+
id: version
47+
run: |
48+
BASE_VERSION=$(jq -r .version package.json)
49+
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7)
50+
PRERELEASE_VERSION="${BASE_VERSION}-staging.${SHORT_SHA}"
51+
echo "version=${PRERELEASE_VERSION}" >> $GITHUB_OUTPUT
52+
echo "Pre-release version: ${PRERELEASE_VERSION}"
5653
5754
- name: Deploy
5855
uses: ./.github/actions/deploy
5956
with:
6057
environment: staging
6158
aws-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
6259
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
60+
env:
61+
VERSION: ${{ steps.version.outputs.version }}
6362

64-
- name: Get versions
65-
id: lambda-version
63+
- name: Summary
6664
run: |
67-
echo "::set-output name=LAMBDA_VERSION::$(./scripts/version.sh get)"
68-
echo "::set-output name=AUTHORIZER_VERSION::$(./scripts/version.sh get)"
69-
70-
- uses: actions/github-script@v7
71-
with:
72-
script: |
73-
github.rest.issues.createComment({
74-
issue_number: context.issue.number,
75-
owner: context.repo.owner,
76-
repo: context.repo.repo,
77-
body: '* [Lambda version](https://nowplaying-${{env.TF_VAR_env}}.lhowsam.com) - `${{ steps.lambda-version.outputs.LAMBDA_VERSION }}`\n* [Authorizer version](https://nowplaying-${{env.TF_VAR_env}}.lhowsam.com) - `${{ steps.lambda-version.outputs.AUTHORIZER_VERSION }}`'
78-
})
65+
echo "## 🚀 Staging Deployment" >> $GITHUB_STEP_SUMMARY
66+
echo "" >> $GITHUB_STEP_SUMMARY
67+
echo "- **Version**: \`${{ steps.version.outputs.version }}\`" >> $GITHUB_STEP_SUMMARY
68+
echo "- **URL**: https://nowplaying-staging.lhowsam.com" >> $GITHUB_STEP_SUMMARY

.github/workflows/build-release-version.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ env:
3131
jobs:
3232
release:
3333
name: Release packages
34-
runs-on: ubuntu-latest
34+
runs-on: macos-latest
3535
timeout-minutes: 10
3636
steps:
3737
- name: Checkout repository

.github/workflows/deploy-test.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Deploy Test (PR Preview)
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
types: [opened, synchronize, reopened]
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
env:
13+
TF_VAR_env: test
14+
TF_VAR_env_vars: ${{ secrets.LIVE_ENV_VARS }}
15+
TF_VAR_zone_id: ${{ secrets.LIVE_ZONE_ID }}
16+
TF_VAR_root_domain: lhowsam.com
17+
TF_VAR_sub_domain: nowplaying.lhowsam.com
18+
TF_VAR_private_key: ${{ secrets.STAGING_PRIVATE_KEY }}
19+
TF_VAR_certificate_body: ${{ secrets.STAGING_CERTIFICATE_BODY }}
20+
TF_VAR_certificate_chain: ${{ secrets.STAGING_CERTIFICATE_CHAIN }}
21+
TF_VAR_deployed_by: ${{ github.actor }}
22+
TF_VAR_git_sha: ${{ github.sha }}
23+
TF_VAR_api_key: ${{ secrets.STAGING_API_KEY }}
24+
TF_VAR_discord_webhook_url: ${{ secrets.DISCORD_ALERTS_WEBHOOK_URL }}
25+
26+
permissions: write-all
27+
28+
jobs:
29+
deploy:
30+
name: Deploy to Test
31+
runs-on: ubuntu-latest
32+
timeout-minutes: 15
33+
steps:
34+
- name: Checkout repository
35+
uses: actions/checkout@v4
36+
with:
37+
fetch-depth: 0
38+
ref: ${{ github.head_ref }}
39+
40+
- name: Ensure rebased with main
41+
run: ./scripts/ensure-rebased.sh
42+
43+
- name: Setup Bun
44+
uses: oven-sh/setup-bun@v2
45+
with:
46+
bun-version-file: ".bun-version"
47+
48+
- name: Install dependencies
49+
run: bun install --frozen-lockfile
50+
51+
- name: Get pre-release version
52+
id: version
53+
run: |
54+
BASE_VERSION=$(jq -r .version package.json)
55+
PR_NUMBER=${{ github.event.pull_request.number }}
56+
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-7)
57+
PRERELEASE_VERSION="${BASE_VERSION}-pr.${PR_NUMBER}.${SHORT_SHA}"
58+
echo "version=${PRERELEASE_VERSION}" >> $GITHUB_OUTPUT
59+
echo "Pre-release version: ${PRERELEASE_VERSION}"
60+
61+
- name: Deploy
62+
uses: ./.github/actions/deploy
63+
with:
64+
environment: ${{ env.TF_VAR_env }}
65+
aws-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
66+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
67+
env:
68+
VERSION: ${{ steps.version.outputs.version }}
69+
70+
- name: Comment on PR
71+
uses: actions/github-script@v7
72+
with:
73+
script: |
74+
const version = '${{ steps.version.outputs.version }}';
75+
const marker = '<!-- test-deployment-comment -->';
76+
const body = `${marker}\n## 🚀 Test Deployment\n\n- **Version**: \`${version}\`\n- **URL**: https://nowplaying-test.lhowsam.com\n- **Health**: https://nowplaying-test.lhowsam.com/api/health\n- **Version API**: https://nowplaying-test.lhowsam.com/api/version`;
77+
78+
// Find existing comment
79+
const { data: comments } = await github.rest.issues.listComments({
80+
owner: context.repo.owner,
81+
repo: context.repo.repo,
82+
issue_number: context.issue.number,
83+
});
84+
85+
const existingComment = comments.find(comment => comment.body.includes(marker));
86+
87+
if (existingComment) {
88+
// Update existing comment
89+
await github.rest.issues.updateComment({
90+
owner: context.repo.owner,
91+
repo: context.repo.repo,
92+
comment_id: existingComment.id,
93+
body: body
94+
});
95+
} else {
96+
// Create new comment
97+
await github.rest.issues.createComment({
98+
owner: context.repo.owner,
99+
repo: context.repo.repo,
100+
issue_number: context.issue.number,
101+
body: body
102+
});
103+
}

0 commit comments

Comments
 (0)