telefonicaid / iotagent-node-lib

Module to enable IoT Agent developers to build custom agents for their devices that can easily connect to NGSI Context Brokers
https://iotagent-node-lib.rtfd.io/
GNU Affero General Public License v3.0
60 stars 87 forks source link

The CI for the library should offer a repository dispatch #1021

Closed jason-fox closed 3 years ago

jason-fox commented 3 years ago

Related to https://github.com/telefonicaid/lightweightm2m-iotagent/pull/248#issuecomment-818647123

At the moment whenever changes are made in the IoT Agent Node library in this repo here, they are not witnessed downstream until a new build is triggered. The CI for this repo should offer a trigger to the IoT Agents whenever code is successfully merged into master. An exisiting GitHub Action can already do this provided that a PAT token is added a a secret within this repository. You'll need something like:

jobs:
  build:
    # Main workflow job that builds, tests, etc.

  dispatch:
    if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true
    strategy:
      matrix:
        repo: ['telefonicaid/iotagent-json, 'telefonicaid/iotagent-ul, 'telefonicaid/iotagent-lightweightm2m-iotagent']
    runs-on: ubuntu-latest
    steps:
      - name: Repository Dispatch
        uses: peter-evans/repository-dispatch@v1
        with:
          token: ${{ secrets.REPO_ACCESS_TOKEN }}
          repository: ${{ matrix.repo }}
          event-type: iot-agent-node-lib

Each of the IoT Agents CI could then be altered to handle both a manual trigger and the iot-agent-node-lib event e.g.:

name: CI
'on':
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
  repository_dispatch:
    types:
      - iot-agent-node-lib
  workflow_dispatch:

This would avoid nasty discoveries if any downstream project is relying on something it shouldn't.

fgalan commented 3 years ago

PRs related with this issue:

GitHub has auto-close this issue, but maybe is wiser to let it opened while we can check that the system is working

jason-fox commented 3 years ago

Even better would be to close it after we've got dispatch working with FIWARE/iotagent-isoxml - I guess you'll need a FIWARE PAT (with minimal rights) from me right? Assuming TEF can dispatch to FF, this should also be extended to informing ATOS (for the LoRaWAN IoT Agent)

fgalan commented 3 years ago

No problem in adding additional token as tokens in this repo... however, how this could be managed in ci.yml? What we have now is:

        with:
          token: ${{ secrets.REPO_ACCESS_TOKEN }}
          repository: ${{ matrix.repo }}
          event-type: iot-agent-node-lib

But I understand more of these secrets.xxxx should be added there (i.e. REPO_ACCESS_TOKEN_FF, REPO_ACCESS_TOKEN_ATOS, etc.).

fgalan commented 3 years ago

IOTAManager was missing. The following PRs cover it:

fgalan commented 3 years ago

Not sure if the system is working properly... Just after merging PR #1104 CI actions we can see at https://github.com/telefonicaid/iotagent-node-lib/runs/3598938988?check_suite_focus=true

imagen

So it seems the dispatch job has not been executed.

In fact, if we see for instance iotagent-ul actions (https://github.com/telefonicaid/iotagent-ul/actions) we can si last action was 2 hours ago...

imagen

Any clue?

jason-fox commented 3 years ago

There is something wrong with the if

if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true

The test run didn't include that filter.

jason-fox commented 3 years ago

It looks like github.event.pull_request.merged has changed - its now just a github.event_name == 'push'

if: ${{ github.ref == 'refs/heads/master' }}

or

if: ${{ github.ref == 'refs/heads/master'  && github.event_name == 'push' }}

should be sufficient

fgalan commented 3 years ago

... or

if: ${{ github.ref == 'refs/heads/master'  && github.event_name == 'push' }}

should be sufficient

Done in PR https://github.com/telefonicaid/iotagent-node-lib/pull/1105

fgalan commented 3 years ago

Much better now (https://github.com/telefonicaid/iotagent-node-lib/actions/runs/12339361849)

imagen

:)

fgalan commented 3 years ago

In the https://github.com/telefonicaid/iotagent-ul/actions page we see a lib-update job:

imagen

So it seems it works!