Skip to content

Commit b055820

Browse files
authored
Create lambda.yml
1 parent e7e613d commit b055820

File tree

1 file changed

+105
-0
lines changed

1 file changed

+105
-0
lines changed

.github/workflows/lambda.yml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: Deploy Lambda@Edge to prod
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Pushpak version to be released'
8+
required: true
9+
type: "string"
10+
11+
jobs:
12+
release_prep:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: 'Get Previous tag'
21+
id: previoustag
22+
uses: "WyriHaximus/github-action-get-previous-tag@v1"
23+
24+
- name: Decide major or minor version
25+
id: compare_versions
26+
run: |
27+
latest_tag=${{ steps.previoustag.outputs.tag }}
28+
current_version=$(echo "$latest_tag" | cut -d'.' -f1 | sed 's/[^0-9]//g')
29+
new_version=$(echo "${{ github.event.inputs.version }}" | cut -d'.' -f1 | sed 's/[^0-9]//g')
30+
echo "new : $new_version"
31+
echo "current: $current_version"
32+
echo "current_version=$current_version" >> $GITHUB_OUTPUT
33+
34+
if [ "$new_version" -gt "$current_version" ]; then
35+
echo "major_version_upgrade=true" >> $GITHUB_OUTPUT
36+
echo "base_branch=main" >> $GITHUB_OUTPUT
37+
else
38+
echo "major_version_upgrade=false" >> $GITHUB_OUTPUT
39+
echo "base_branch=$current_version.0.0" >> $GITHUB_OUTPUT
40+
fi
41+
env:
42+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
43+
44+
# if the version is not major then checkout current feature branch
45+
- name: checkout current feature branch
46+
if: steps.compare_versions.outputs.major_version_upgrade == 'false'
47+
uses: actions/checkout@v4
48+
with:
49+
ref: "${{ steps.compare_versions.outputs.current_version}}.0.0"
50+
51+
- name: "Cut out a new feature branch for major release"
52+
if: steps.compare_versions.outputs.major_version_upgrade == 'true'
53+
run: |
54+
# Cut a new feature branch from main
55+
git config --local user.email "${{ github.repository_owner }}@users.noreply.github.com"
56+
git config --local user.name "GitHub Actions"
57+
git switch -c ${{ github.event.inputs.version }}
58+
git push origin ${{ github.event.inputs.version }}
59+
env:
60+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61+
62+
- name: Prepare staging directory
63+
run: |
64+
rm -rf staging
65+
mkdir -p staging
66+
cp -r src/* staging/
67+
pip install -r requirements.txt -t staging
68+
69+
- name: Package viewer_request Lambda
70+
run: |
71+
cd staging
72+
zip ../viewer_request.zip -j edge_functions/viewer_request.py
73+
cd ..
74+
75+
- name: Package origin_request Lambda
76+
run: |
77+
cd staging
78+
zip -r ../origin_request.zip . -x edge_functions/viewer_request.py
79+
cd ..
80+
81+
- name: "Create release"
82+
run: |
83+
echo "$base_branch"
84+
85+
gh release create v${{ github.event.inputs.version }} \
86+
--title v${{ github.event.inputs.version }} \
87+
--target ${{ github.event.inputs.version }} \
88+
viewer_request.zip origin_request.zip origin_response.zip
89+
env:
90+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
91+
92+
#- name: Upload ZIPs to S3
93+
# env:
94+
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
95+
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
96+
# AWS_REGION: "us-east-1"
97+
# run: |
98+
# S3_BUCKET="pushpak-lambda-source"
99+
# VIEWER_REQUEST_ZIP="viewer_request_prod.zip"
100+
# ORIGIN_REQUEST_ZIP="origin_request_prod.zip"
101+
# ORIGIN_RESPONSE_ZIP="origin_response_prod.zip"
102+
103+
# aws s3 cp viewer_request.zip s3://$S3_BUCKET/$VIEWER_REQUEST_ZIP
104+
# aws s3 cp origin_request.zip s3://$S3_BUCKET/$ORIGIN_REQUEST_ZIP
105+
# aws s3 cp origin_response.zip s3://$S3_BUCKET/$ORIGIN_RESPONSE_ZIP

0 commit comments

Comments
 (0)