Merge pull request #86 from KoalaBotUK/fix/issue-25-post-link-user-li… #112
This file contains hidden or 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: API Lambda Deploy ⁁ | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - api/** | |
| - .github/workflows/api-deploy.yml | |
| tags: | |
| - '*.*.*' | |
| workflow_dispatch: {} | |
| permissions: | |
| contents: read | |
| jobs: | |
| build-deploy: | |
| environment: ${{ github.ref == 'refs/heads/main' && 'dev' || 'prod' }} | |
| name: Build & Deploy 📦 | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup AWS CLI | |
| uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502 # v4.0.2 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: ${{ secrets.AWS_REGION }} | |
| - name: Rust Cache | |
| uses: Swatinem/rust-cache@v2 | |
| - name: Install cargo-lambda | |
| uses: jaxxstorm/action-install-gh-release@v1 | |
| with: | |
| repo: cargo-lambda/cargo-lambda | |
| - name: Install Zig | |
| run: npm install -g @ziglang/cli | |
| - name: Install dependencies | |
| run: cargo install sqlx-cli | |
| - name: Build | |
| run: cargo lambda build --release --output-format zip -p api -p consumer | |
| - name: Migrate Database | |
| env: | |
| DSQL_ENDPOINT: ${{ secrets.DSQL_ENDPOINT }} | |
| run: | | |
| cd api | |
| token=$(aws dsql generate-db-connect-admin-auth-token --hostname $DSQL_ENDPOINT) | |
| encoded_token=$(echo "$token" | jq -Rr @uri) | |
| sqlx migrate run --database-url "postgresql://admin:${encoded_token}@${DSQL_ENDPOINT}/postgres?sslmode=require" | |
| cd .. | |
| - name: Upload api to Lambda | |
| run: aws lambda update-function-code --function-name kb2-lambda-function-${{ github.ref == 'refs/heads/main' && 'dev' || 'prod' }} --zip-file fileb://target/lambda/api/bootstrap.zip | |
| - name: Upload consumer to Lambda | |
| run: aws lambda update-function-code --function-name kb2-lambda-consumer-${{ github.ref == 'refs/heads/main' && 'dev' || 'prod' }} --zip-file fileb://target/lambda/consumer/bootstrap.zip |