Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doesn't seems to do what it should #12

Closed
nimroda opened this issue Jul 4, 2023 · 7 comments
Closed

doesn't seems to do what it should #12

nimroda opened this issue Jul 4, 2023 · 7 comments

Comments

@nimroda
Copy link

nimroda commented Jul 4, 2023

I've tried using this action in my workflow which consists of multiple jobs.
when more than 2 workflows are triggered , the second one gets canceled by GitHub.
it doesn't seem to work or I'm missing something.

@ben-z
Copy link
Owner

ben-z commented Jul 4, 2023

Can you provide an MRE?

I’m guessing your concurrency group is defined with cancel-in-progress set to true.

@nimroda
Copy link
Author

nimroda commented Jul 9, 2023

Hi ben-z, thanks for answering.
cancel-in-progress is set to false in my workflow.
here's my workflow, i've changed all secrets to "XXX"

name: Test E2E Staging
on:
  workflow_dispatch:
    inputs:
      repost_to_slack:
        description: 'Report on slack'
        required: true
        type: boolean
        default: true
      env:
        description: 'Target environment'
        required: true
        type: choice
        default: 'staging'
        options:
        - staging
      triggered_from:
        description: 'Which repo triggered the test'
        required: true
        type: choice
        default: 'devops-tools'
        options:
        - devops-tools
        - search
        - mono-client
        - crm-integrations
        - litebound
        - common
  workflow_call:
    inputs:
      repost_to_slack:
        description: 'Report on slack'
        required: true
        type: boolean
        default: true
      env:
        description: 'Target environment'
        required: true
        type: string
        default: 'staging'
      triggered_from:
        description: 'Which repo triggered the test'
        required: true
        type: string
        default: 'devops-tools'

env:
   TEST_FUNCTION: "litebound-staging-delete_lifter_customer_data"
permissions:
   id-token: write
   contents: read
concurrency:
  group: lifter-tests-staging-concurrency
  cancel-in-progress: false

jobs:
  start-deployment-notification:
    runs-on: ubuntu-latest
    steps:
      - name: Get current time
        uses: josStorer/get-current-time@v2.0.2
        id: current-time
        with:
          format: YYYYMMDD-HH
          utcOffset: "+02:00"
      - name: Map Inputs
        run: |
          echo "### \`map_inputs\`"                                                                     >> $GITHUB_STEP_SUMMARY
          echo "Environment=${{ github.event.inputs.env || inputs.env }}"                               >> $GITHUB_STEP_SUMMARY
          echo "Branch=${{ github.ref }}"                                                               >> $GITHUB_STEP_SUMMARY
          echo "Run By=${{ github.actor }}"                                                             >> $GITHUB_STEP_SUMMARY
          echo "Deploy Time=${{ steps.current-time.outputs.readableTime }}"                             >> $GITHUB_STEP_SUMMARY
          echo "Triggered From=${{ github.event.inputs.triggered_from || inputs.triggered_from }} repo" >> $GITHUB_STEP_SUMMARY          
      # Post on slack
      - name: Post on slack
        uses: act10ns/slack@v2.0.0
        if: ${{ github.event.inputs.repost_to_slack == 'true'}}
        env:
          SLACK_WEBHOOK_URL: ${{ XXX }}
        with:
          status: ${{ job.status }}
          message: |
            ${{github.actor}} have *started* to invoke Lifter UI E2E Tests on ${{ github.event.inputs.env || inputs.env }}.
            You can view the job here ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}

  invoke_before:
    needs: [start-deployment-notification]
    name: Invoke litebound-staging-delete_lifter_customer_data in environment ${{ github.event.inputs.env || inputs.env }}
    timeout-minutes: 60
    runs-on: ubuntu-latest
    steps:

    - name: print inputs
      run: |
        echo "env: ${{ github.event.inputs.env || inputs.env }}"
        echo "branch: ${{ github.ref }}"

    - name: Setup folder and role for staging Env
      run: |
          echo "TARGET_ENV=${{ github.event.inputs.env || inputs.env }}" >> $GITHUB_ENV
          echo "SLACK_WEBHOOK_URL=${{ XXX }}" >> $GITHUB_ENV
          echo "role=${{ XXX }}" >> $GITHUB_ENV

    - name: echo target environment
      run: |
          echo "-------------------------------------------------------------------"
          echo "using *********** ${{ env.TARGET_ENV }} *********** as target env"
          echo "--------------------------------------------------------------------"

    - name: checkout
      uses: actions/checkout@v3
      with:
        fetch-depth: 0

    - name: Set up mutex
      uses: ben-z/gh-action-mutex@v1.0-alpha-7
      with:
        branch: main

    - name: Configure staging aws credentials
      uses: aws-actions/configure-aws-credentials@v1-node16
      with:
        role-to-assume: ${{ XXX }}
        role-session-name: GitHubActions-session-${{ github.run_id }}-${{ github.run_attempt }}
        aws-region: ${{ secrets.REGION }}

    - name: Invoke ${{ env.TEST_FUNCTION }}
      id: invoke_function
      run: |
          aws lambda invoke \
            --function-name ${{ env.TEST_FUNCTION }} \
            --cli-binary-format raw-in-base64-out \
            --payload '{ "rb_customer_name": "qatestlifter" }' \
            /dev/null --log-type Tail > test.json
      continue-on-error: true 

      # Check DB Migration status
    - name: Check invoke lambda status
      run: |
        if ( grep -q 200 test.json && ! grep -q FunctionError test.json ) ; then
          echo "DB Migrator done"
          cat test.json
        else
          echo 'Invoke function failed, check ${{ env.TEST_FUNCTION }} logs for details...'
          cat test.json
          exit 1
        fi

    - name: Sleep for 60 seconds
      uses: whatnick/wait-action@master
      with:
        time: '60s'

  run-testimio-cli:
      runs-on: ubuntu-latest
      needs: [invoke_before]
      steps:
          - uses: actions/checkout@v3
          - uses: actions/setup-node@v3.5.1
            with:
              node-version: '16.13.0'
          - run: npm install -g @testim/testim-cli
          - name: Execute testim suites
            run: |
              testim --result-label ${{ github.event.inputs.triggered_from || inputs.triggered_from }} --token ${{ XXX }} --project "XXX" --grid "Testim-Grid" --suite "Staging env"

  slack-workflow-status:
    if: always()
    name: Post Workflow Status To Slack
    needs:
      - start-deployment-notification
      - invoke_before
      - run-testimio-cli
    runs-on: ubuntu-latest
    steps:
    - name: Slack Workflow Notification
      uses: Gamesight/slack-workflow-status@master
      if: ${{ github.event.inputs.repost_to_slack == 'true' }}
      with:
        repo_token: ${{ XXX }}
        slack_webhook_url: ${{ XXX }}

@ben-z
Copy link
Owner

ben-z commented Jul 9, 2023

Can you indent the code properly in your message? I’d use triple backticks.

I see that the branch argument is set to main. Is that intentional? This will use the main branch as the branch to store locks. Usually, we use a separate, empty branch.

@nimroda
Copy link
Author

nimroda commented Jul 9, 2023

code was indented properly.
main branch was used on purpose. (I can change it to use a dedicated branch if it's best practice)

@ben-z
Copy link
Owner

ben-z commented Jul 9, 2023

Oh I see, you said

more than 2 workflows

You probably want to not use a concurrency group if you want to have the same workflow protected by a mutex. Just removing the concurrency line should result in what you want.

@nimroda
Copy link
Author

nimroda commented Jul 10, 2023

Thanks ben-z , it seems to lock a job in the workflow when concurrency group is commented out.
But it looks like I need to add the mutex action once in every job .

@ben-z
Copy link
Owner

ben-z commented Jul 10, 2023

Ah yep, the mutex works at a job-level and not at a workflow-level. This is mainly because there's no easy way to achieve RAII at a workflow level. It could be possible, but it'd require some investigation.

@ben-z ben-z closed this as completed Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants