metacall / core

MetaCall: The ultimate polyglot programming experience.
https://metacall.io
Apache License 2.0
1.56k stars 160 forks source link

Connect Core CI with Distributable's Repo #505

Closed shaggyyy2002 closed 1 month ago

shaggyyy2002 commented 3 months ago

🚀 Feature

Consistent CI across multiple repositories in order to provide continuous delivery of MetaCall binaries with report of errors for when some distributable fails on a version of MetaCall Core.

Is your feature request related to a problem?

Earlier when a new tag was being pushed it would only trigger the core repo CI to build binaries. Adding a new CI in which when a new tag is pushed and repo is built successfully then it will trigger the distributable repo's (windows/linux/macos) to build new binaries with newer version/tags.

Describe the solution you'd like

My current solution uses github.com/peter-evans/repository-dispatch@v2. Where we can use this Github Action to trigger in remote repo

Dispatch to multiple repositories. You can dispatch to multiple repositories by using a matrix strategy. In the following example, after the build job succeeds, an event is dispatched to three different repositories.

    strategy:
      matrix:
        repo: ['metacall/distributable-windows', 'metacall/distributable-linux', 'metacall/distributable-macos']
shaggyyy2002 commented 3 months ago

using this under the release.yml file so that dispatch runs when the release.yml file is build as mentioned needs: build. if created a separate file for this it may sometimes run first or last as its picked or we would need to use if else statements, this is more easy.

name: Release

on:
  push:
    tags:
    - 'v*.*.*'

concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
  cancel-in-progress: true

env:
  GHR_VERSION: 0.12.0
  IMAGE_NAME: index.docker.io/metacall/core
  IMAGE_REGISTRY: index.docker.io
  ARTIFACTS_PATH: ./build-artifacts
  # GITHUB_TOKEN      - From default secrets
  # GITHUB_REPOSITORY - Default variable

jobs:
  build:
    name: Build the core
    runs-on: ubuntu-latest
    steps:
      - name: Check out the repo
        uses: actions/checkout@v4
.
.
.
. [continued in core]
.
.
 dispatch:
    needs: build
    strategy:
      matrix:
        repo: ['company/repo1', 'company/repo2', 'company/repo3']
    runs-on: ubuntu-latest
    steps:
      - name: Repository Dispatch
        uses: peter-evans/repository-dispatch@v3
        with:
          token: ${{ secrets.ACCESS_TOKEN }}
          repository: ${{ matrix.repo }}
          event-type: test-trigger   

This is what it would look like:

Screenshot 2024-06-04 at 10 12 29 PM
shaggyyy2002 commented 3 months ago

We are not using release.yml file that often so 2 possible solution left.

  1. Create a separate yml file
name: CI Signal to other dist repos

on:
  push:
    tags:
      - 'v*'

jobs:
  check_completion:
    runs-on: ubuntu-latest
    outputs:
      {other OS}
      windows_success: ${{ steps.windows.outputs.success }}
> {Other OS checks}
      - name: Check Windows Test Completion
        id: windows
        if: github.event.workflow_run.name == 'Windows Test'
        run: |
          echo "::set-output name=success::${{ github.event.workflow_run.conclusion == 'success' }}"

  dispatch_windows:
    if: ${{ steps.check_completion.outputs.windows_success == 'true' }}
    runs-on: ubuntu-latest
    steps:
      - name: Windows Repository Dispatch
        uses: peter-evans/repository-dispatch@v3
        with:
          token: ${{ secrets.ACCESS_TOKEN }}
          repository: shaggyyy2002/distributable-windows
          event-type: test-trigger
  1. Add the code to the test files, so that when the test completes, it then trigger to that distributable repo eg. Windows test successful -> triggers -> dist-windows
    
    trigger_dist_windows:
    needs: windows-test
    if: ${{ success() }}
    runs-on: ubuntu-latest
    steps:
      - name: Windows Repository Dispatch
        uses: peter-evans/repository-dispatch@v3
        with:
          token: ${{ secrets.ACCESS_TOKEN }}
          repository: metacall/distributable-windows
          event-type: test-trigger
          ref: ${{ github.ref }}

To solve the issue, I am using the 2 one so that no need to write extra code and logic. The first one (creating a separate file) would've required us to write something to make sure our dist repo triggers when all the checks and tests are passed. So choosing the 2nd option 

---
✅ Our commit & tag when pushed it did trigger the dist repo. 
❌ The error facing right now is in the dist repo to release it, it needs a git tag, which is being passed  from the core repo but its not accessible from the dist repos. 
shaggyyy2002 commented 2 months ago

some minor changes: we are using client-payload: '{"ref": "${{ github.ref }}"}' the earlier ref: ${{ github.ref }} is deprecated for v3 dispatch. More info : https://github.com/peter-evans/repository-dispatch

shaggyyy2002 commented 2 months ago

On the core repo its done.

  1. A tag when pushed and the testCI is passed (in core repo) only then it will trigger the remote distributable repo (linux, window, mac) to make the dist repo accept the req. (image from core repo LinuxCI) Screenshot 2024-06-21 at 2 28 19 AM
  2. Now we need to change the CI in the dist repo so that when the trigger reaches it will start the CI process of that repo

changes needed on the dist repo's

name: "MetaCall Distributable Release"

on:
  repository_dispatch:
    types: [test-trigger]

(Image from linux-dist repo)

Screenshot 2024-06-21 at 2 31 07 AM
shaggyyy2002 commented 2 months ago
Screenshot 2024-06-28 at 9 05 33 PM