go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/.github/workflows/providers.yaml (about)

     1  name: 'Build & Release Providers'
     2  
     3  on:
     4    push:
     5      branches: ['main']
     6      paths: ['providers/**']
     7    workflow_dispatch:
     8      inputs:
     9        build_all:
    10          description: 'Force build all providers'
    11          type: boolean
    12          required: false
    13          default: 'false'
    14        skip_publish:
    15          description: 'Skip publishing'
    16          type: boolean
    17          required: false
    18          default: 'false'
    19  
    20  
    21  env:
    22    BUCKET: releases-us.mondoo.io
    23    SKIP_PROVIDERS: "core"
    24  
    25  jobs:
    26    scoping:
    27      name: "Scoping"
    28      runs-on: self-hosted
    29      timeout-minutes: 10
    30      outputs:
    31        providers: ${{ steps.providers.outputs.providers }}
    32      steps:
    33        - name: Checkout
    34          uses: actions/checkout@v4
    35          with:
    36            fetch-depth: 0
    37        - name: Detect providers
    38          id: providers
    39          run: |
    40            providers=$(find providers -mindepth 1 -maxdepth 1 -type d -exec basename {} \;)
    41            build=""
    42            root=$PWD
    43            for p in $providers; do
    44              skip=0
    45              for s in $SKIP_PROVIDERS; do
    46                if [[ $p == $s ]]; then
    47                  skip=1
    48                fi
    49              done
    50              if [[ $skip == 1 ]]; then
    51                echo "$p is on the skip list. Skipping."
    52                continue
    53              fi
    54              cd providers/$p
    55              REPO_VERSION=$(grep Version config/config.go | cut -f2 -d\")
    56              DIST_VERSION=$(curl -s https://releases.mondoo.com/providers/${p}/latest.json | jq -r .version)
    57              printf "PROVIDER $p:\n  Local version: $REPO_VERSION\n  Remote version: $DIST_VERSION\n"
    58              if [[ $REPO_VERSION != $DIST_VERSION ]]; then
    59                echo "  Adding $p to build list"
    60                build="$build $p"
    61              else
    62                echo "  Skipping: Provider version unchanged."
    63              fi
    64              cd $root
    65            done
    66  
    67            echo "providers=$(echo -n $build | jq -Rsc 'split(" ")')" >> $GITHUB_OUTPUT
    68  
    69            build_all=${{ github.event.inputs.build_all }}}
    70            if [[ $build_all ]]; then
    71              echo "Forced build of all providers"
    72              printf '%s\n' "${providers[@]}" | jq -R . | jq -sc . > providers.json
    73              echo "providers=$(cat providers.json)" >> $GITHUB_OUTPUT
    74            fi
    75  
    76            echo "Providers detected:"
    77            echo $providers
    78  
    79            echo "Providers to build:"
    80            echo $build
    81  
    82    provider-build:
    83      name: "${{ matrix.provider }}"
    84      runs-on: self-hosted
    85      timeout-minutes: 120
    86      needs: scoping
    87      strategy:
    88        max-parallel: 2
    89        matrix:
    90          provider: ${{ fromJSON(needs.scoping.outputs.providers) }}
    91      steps:
    92        - name: Checkout
    93          uses: actions/checkout@v4
    94          with:
    95            fetch-depth: 0
    96  
    97        - name: Set up Go
    98          uses: actions/setup-go@v4
    99          with:
   100            go-version: ">=1.21.0"
   101            cache: false
   102  
   103        - name: 'Authenticate to Google Cloud'
   104          uses: 'google-github-actions/auth@v1'
   105          with:
   106            credentials_json: ${{ secrets.GCP_RELEASE_SERVICE_ACCOUNT}}
   107  
   108        - name: 'Set up gcloud CLI'
   109          uses: 'google-github-actions/setup-gcloud@v1'
   110  
   111        - name: 'Build dependencies'
   112          run: |
   113            make providers/proto
   114            go build -o lr ./providers-sdk/v1/lr/cli/main.go
   115  
   116        - name: 'Build Provider'
   117          run: |
   118            rm -rf ./dist
   119            scripts/provider_bundler.sh ${{ matrix.provider }}
   120  
   121        - name: 'Publish Provider'
   122          if: ${{ github.event.inputs.skip_publish == 'false' }}
   123          run: |
   124            for pkg in $(ls dist | cut -f1,2 -d_ | uniq); do
   125              PROVIDER=$(echo $pkg | cut -f1 -d_)
   126              VERSION=$(echo $pkg | cut -f2 -d_)
   127              echo "Publishing $pkg: $PROVIDER $VERSION"
   128  
   129              echo "Publishing $pkg to gs://${BUCKET}/providers/${PROVIDER}/${VERSION}/"
   130              gsutil -m cp -c dist/${pkg}*.xz gs://${BUCKET}/providers/${PROVIDER}/${VERSION}/
   131              gsutil -m cp -c dist/${pkg}_SHA256SUMS gs://${BUCKET}/providers/${PROVIDER}/${VERSION}/
   132            done
   133  
   134        - name: 'Save Artifacts'
   135          if: ${{ github.event.inputs.skip_publish == 'true' }}
   136          uses: actions/upload-artifact@v3
   137          with:
   138            name: ${{ matrix.provider }}
   139            path: dist
   140  
   141    provider-index:
   142      needs: [provider-build, scoping]
   143      runs-on: self-hosted
   144      steps:
   145        - name: Trigger Reindex of releases.mondoo.com
   146          uses: peter-evans/repository-dispatch@v2
   147          with:
   148            token: ${{ secrets.RELEASR_ACTION_TOKEN }}
   149            repository: "mondoohq/releasr"
   150            event-type: reindex
   151            client-payload: '{ }'