|
| 1 | +name: Test and Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main, dev, test] |
| 6 | + |
| 7 | +jobs: |
| 8 | + |
| 9 | + run-tests: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + # Checks-out your repository under $GITHUB_WORKSPACE |
| 13 | + - name: Check out repository |
| 14 | + uses: actions/checkout@v3 |
| 15 | + |
| 16 | + - name: Configure AWS Credentials |
| 17 | + uses: aws-actions/configure-aws-credentials@v1-node16 |
| 18 | + with: |
| 19 | + aws-access-key-id: ${{ secrets.SLS_AWS_ACCESS_KEY_ID }} |
| 20 | + aws-secret-access-key: ${{ secrets.SLS_AWS_SECRET_ACCESS_KEY }} |
| 21 | + aws-region: us-east-1 |
| 22 | + |
| 23 | + # Set up Python 3.9 environment |
| 24 | + - name: Set up Python |
| 25 | + uses: actions/setup-python@v4 |
| 26 | + with: |
| 27 | + python-version: 3.9 |
| 28 | + |
| 29 | + # Install Python dependencies |
| 30 | + - name: Install Dependencies |
| 31 | + run: | |
| 32 | + python -m pip install --upgrade pip |
| 33 | + pip install -r requirements.txt |
| 34 | + |
| 35 | + # Run tests |
| 36 | + - name: Run tests |
| 37 | + run: python -m pytest |
| 38 | + |
| 39 | + |
| 40 | + deploy: |
| 41 | + needs: |
| 42 | + - run-tests |
| 43 | + runs-on: ubuntu-latest |
| 44 | + steps: |
| 45 | + |
| 46 | + # Configure the deployment stage name from the active branch |
| 47 | + - name: Set up deployment stage name |
| 48 | + id: deployment-stage |
| 49 | + run: | |
| 50 | + echo "DEPLOY_STAGE=${{ fromJSON('{"main":"prod","dev":"dev","test":"test"}')[github.ref_name] }}" >> $GITHUB_ENV |
| 51 | +
|
| 52 | + - name: Verify Stage |
| 53 | + run: echo $DEPLOY_STAGE |
| 54 | + |
| 55 | + # Checks-out the repository under $GITHUB_WORKSPACE |
| 56 | + - uses: actions/checkout@v2 |
| 57 | + |
| 58 | + # Configure Auth0 secrets |
| 59 | + - name: Create public_key file |
| 60 | + run: | |
| 61 | + cat > /home/runner/work/photonranch-api/photonranch-api/public_key << EOF |
| 62 | + -----BEGIN CERTIFICATE----- |
| 63 | + ${{ secrets.AUTH0_PUBLIC_KEY }} |
| 64 | + -----END CERTIFICATE----- |
| 65 | + EOF |
| 66 | + |
| 67 | + - name: Create Auth0 secrets file |
| 68 | + run: | |
| 69 | + cat > /home/runner/work/photonranch-api/photonranch-api/secrets.json << EOF |
| 70 | + { |
| 71 | + "AUTH0_CLIENT_ID": "${{ secrets.AUTH0_CLIENT_ID }}" |
| 72 | + } |
| 73 | + EOF |
| 74 | +
|
| 75 | + # Set up Node |
| 76 | + - name: Set up Node |
| 77 | + uses: actions/setup-node@v3 |
| 78 | + with: |
| 79 | + node-version: 16.x |
| 80 | + |
| 81 | + # Set up Python 3.9 environment |
| 82 | + - name: Set up Python |
| 83 | + uses: actions/setup-python@v4 |
| 84 | + with: |
| 85 | + python-version: 3.9 |
| 86 | + |
| 87 | + # Install serverless |
| 88 | + - name: Install Serverless |
| 89 | + run: npm install -g serverless |
| 90 | + |
| 91 | + # Install Node dependencies |
| 92 | + - name: Set up Environment |
| 93 | + run: npm ci |
| 94 | + |
| 95 | + # Install Serverless plugins |
| 96 | + - name: Install Plugins |
| 97 | + run: | |
| 98 | + serverless plugin install --name serverless-python-requirements && |
| 99 | + serverless plugin install --name serverless-domain-manager && |
| 100 | + serverless plugin install --name serverless-prune-plugin && |
| 101 | + serverless plugin install --name serverless-offline |
| 102 | + |
| 103 | + # Deploy to stage |
| 104 | + - name: Serverless Deploy |
| 105 | + run: serverless deploy --stage $DEPLOY_STAGE |
| 106 | + env: |
| 107 | + SERVERLESS_ACCESS_KEY: ${{ secrets.SLS_SECRET_KEY }} |
| 108 | + AWS_ACCESS_KEY_ID: ${{ secrets.SLS_AWS_ACCESS_KEY_ID }} |
| 109 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.SLS_AWS_SECRET_ACCESS_KEY }} |
0 commit comments