fix deployment CI #543
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: deploy lambda functions | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
on: | |
push: { branches: [main] } | |
jobs: | |
deploy-lambdas: | |
runs-on: ubuntu-latest | |
container: swift:6.0-amazonlinux2 | |
env: | |
AWS_DEFAULT_REGION: eu-west-1 | |
AWS_ACCESS_KEY_ID: ${{ secrets.DEPLOYER_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.DEPLOYER_ACCESS_SECRET_KEY }} | |
steps: | |
- name: Install additional dependencies and AWSCLI v2 | |
run: | | |
yum -y install \ | |
{libuuid,libicu,libedit,sqlite,python,ncurses,openssl}-devel \ | |
libtool jq zip | |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" | |
unzip awscliv2.zip | |
./aws/install | |
- name: Check out repository | |
# uses: actions/checkout@v3 ❌ Needs node 20 which amazonlinux2 doesn't have | |
run: | | |
git clone https://github.com/${{ github.repository }} | |
cd ${{ github.event.repository.name }} | |
git checkout ${{ github.sha }} | |
- name: Restore .build | |
if: false # ❌ Needs node 20 which amazonlinux2 doesn't have | |
id: "restore-cache" | |
uses: actions/cache/restore@v4 | |
with: | |
path: ${{ github.event.repository.name }}/.build | |
key: "lambdas-build-${{ runner.os }}-${{ github.event.after }}" | |
restore-keys: "lambdas-build-${{ runner.os }}-" | |
- name: Find package names | |
working-directory: ${{ github.event.repository.name }} | |
id: find_package_names | |
run: | | |
echo "names=$( | |
swift package describe --type json | \ | |
jq -r '.targets[] | | |
select( | |
.type == "executable" | |
and | |
(.name | endswith("Lambda")) | |
).name' | \ | |
tr '\n' ' ' | |
)" >> $GITHUB_OUTPUT | |
- name: Build and package | |
working-directory: ${{ github.event.repository.name }} | |
run: | | |
mkdir zips | |
for name in ${{ steps.find_package_names.outputs.names }}; do | |
swift package archive \ | |
--verbose \ | |
--output-path ./zips \ | |
--products "${name}" | |
aws s3api put-object \ | |
--bucket penny-lambdas-store \ | |
--key "${name}.zip" \ | |
--body ./zips/${name}/${name}.zip | |
done | |
- name: Cache .build | |
if: false # ❌ Needs node 20 which amazonlinux2 doesn't have | |
uses: actions/cache/save@v4 | |
with: | |
path: ${{ github.event.repository.name }}/.build | |
key: "lambdas-build-${{ runner.os }}-${{ github.event.after }}" | |
- name: Deploy | |
working-directory: ${{ github.event.repository.name }} | |
run: | | |
for name in ${{ steps.find_package_names.outputs.names }}; do | |
aws lambda update-function-code \ | |
--function-name "${name}" \ | |
--s3-bucket "penny-lambdas-store" \ | |
--s3-key "${name}.zip" | |
done |