codemagic-ci-cd / trigger-codemagic-workflow-action

GitHub Action to trigger a workflow on Codemagic CI/CD
https://codemagic.io
MIT License
25 stars 2 forks source link

Action is not using existing workflow created in codemagic #8

Closed SegunRova closed 6 months ago

SegunRova commented 6 months ago

I'm using the action to trigger codemagic on repository dispatch.

  1. I have created the workflow in codemagice and applied the necessary configuration (I executed a manual build and it was successful)
  2. I have specified the following in my actions

However, when the action is triggered it does not use the existiong workflow created above, it tries to create a new one with a suffix file in the name, this makes codemagic to fail with error workflow not found.

Please what I'm i doing wrong.

icarusdust commented 6 months ago

Hi @SegunRova, I just gave it a try and it worked as expected. Please check if you are following the same steps as I did:

  1. Placed the following configuration in .github/workflows/main.yml:
on: push

jobs:
  trigger-codemagic-build:
    runs-on: ubuntu-latest
    steps:
      - name: Trigger Codemagic build
        uses: codemagic-ci-cd/trigger-codemagic-workflow-action@v2.0.0
        with:
          app-id: <MY-APPLICATION-ID>
          workflow-id: <MY-WORKFLOW-ID>
          token: ${{ secrets.CODEMAGIC_API_TOKEN }}
  1. Entered app-id: Can be found in the tab URL (https://codemagic.io/app/MY_APP_ID/build/MY_BUILD_ID), workflow-id: If working with codemagic.yaml, then it can be found in YAML:
    workflows:
    ios-workflow: => THIS IS WORKFLOW_ID
      name: ios_workflow
      instance_type: mac_mini_m2

    If working with the workflow editor, it is in the tab url (https://codemagic.io/app/APP_ID/workflow/WORKFLOW_ID/settings) and token: Can be found in Teams > Personal Account > Integrations > Codemagic API

  1. Merged a pull request, then the given workflow got triggered.
SegunRova commented 6 months ago

Hi @icarusdust , thank you for your response. yes I'm following the steps excepts that the file is not named main.yml, below is what my configuration file looks like

name: Integration test

# This workflow is triggered on pushes to the repository.
on:
  repository_dispatch:
    types: [go-integration-test, java-integration-test]

jobs:
  services_job:
    name: integration-test
    runs-on: ubuntu-latest
    permissions:
      contents: read
      packages: write
    steps:

      - name: check out to repository
        uses: actions/checkout@v3
        with:
          repository: roava/app
          token: ${{ secrets.PAT }}

      - uses: subosito/flutter-action@v2
        with:
          flutter-version: '3.16.9'
          channel: 'stable'

      - name: Trigger Codemagic build
        uses: codemagic-ci-cd/trigger-codemagic-workflow-action@v2.0.0
        with:
          app-id: <MY-APPLICATION-ID>
          workflow-id: ${{ github.event.client_payload.name }} # this resolves to the name of the workflow i already created in codemagine i.e ms.test
          branch: 'develop'
          token: ${{ secrets.CODEMAGIC_API_TOKEN }}
icarusdust commented 6 months ago

The problem here is about what workflow-id is resolved to. When applying a different workflow name than the actual one, you can reproduce more or less the same error regarding non-existing workflow. So,${{ github.event.client_payload.name }} is resolved to an incorrect workflow name. Try it with the actual name, it should work.

SegunRova commented 6 months ago

Hi @icarusdust , I updated the pipeline to include the actual name but stll got the same error. it keep adding fromfile to the name

image
icarusdust commented 6 months ago

@SegunRova, it is not adding it to the workflow name, it refers to codemagic.yaml where the build configs are from, you can ignore it.

So, the error is reproducible only when the given workflow name is incorrect.

Screenshot 2024-04-18 at 13 09 45
SegunRova commented 6 months ago

Thank you sir, could it be that the API token is wrong, maybe the user which API token is been used does not have access to that workflow?

icarusdust commented 6 months ago

If the token is incorrect, you will receive Error: Request failed with status code 401: FORBIDDEN, it won't proceed with the trigger.

SegunRova commented 6 months ago

Thank you @icarusdust , I found out the issue. The API triggers workflows created from a codemagic.yaml file, if does not trigger a workflow created from the workflow editor. Thank you for your time.