2

This is similar to what is being asked here but with more explanation and desire for an up-to-date answer (answer uses set-env which is now deprecated)

Say I have the following github action yaml:

name: pull-request-pipeline
on: [pull_request]
jobs:
  deploy-to-dev-and-test:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout action
        uses: actions/checkout@v2

      - name: Configure AWS credentials
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: us-west-2

      - name: Update API gateway definitions
        run: |
          aws apigateway put-rest-api --rest-api-id xxxxxxxx --mode merge --body 'file://SummitApi.yaml'

      - name: Get and store current deploymentId
        run: |
          OLD_DEPLOYMENT_ID=$(aws apigateway get-stage --rest-api-id xxxxxxxx --stage-name dev --query deploymentId --output text)
          echo '::set-output name=OLD_DEPLOYMENT_ID::$OLD_DEPLOYMENT_ID'
        id: old-deployment-id

      - name: Echo old deployment before deploy
        run: |
          echo ${{ steps.old-deployment-id.outputs.OLD_DEPLOYMENT_ID }}

      - name: Deploy to dev stage
        run: |
          aws apigateway create-deployment --rest-api xxxxxxxx --stage-name dev

      - name: Echo old deployment id after deploy
        run: |
          echo ${{ steps.old-deployment-id.outputs.OLD_DEPLOYMENT_ID }} 

When this runs it produces the following:

enter image description here

When taking another approach, specifically changing the Get and store current deploymentId step to:

      - name: Get and store current deploymentId
        run: |
          OLD_DEPLOYMENT_ID=$(aws apigateway get-stage --rest-api-id xxxxxxxx --stage-name dev --query deploymentId --output text)
          echo '::set-output name=OLD_DEPLOYMENT_ID::$OLD_DEPLOYMENT_ID'
        id: old-deployment-id

I get the following:

enter image description here

It seems like it sets the value of the output for the action to the unevaluated definitions of either $OLD_DEPLOYMENT or $(aws apigateway get-stage --rest-api-id xxxxxxxx --stage-name dev --query deploymentId --output text). I want to be able to store the value of the evaluated definition or in this case the actual deployment id from the cmd $(aws apigateway get-stage --rest-api-id xxxxxxxx --stage-name dev --query deploymentId --output text). Any ideas on how to do this with github actions?

References:

https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions

l33tHax0r
  • 1,384
  • 1
  • 15
  • 31

0 Answers0