github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/.github/workflows/build-packages.yml (about)

     1  name: Build packages
     2  # Big chunk of the build process logic is in the mage build targets
     3  on:
     4    workflow_call:
     5    push:
     6      branches: [master]
     7      tags:
     8        - '*'
     9    schedule:
    10      - cron: '0 2 * * *'
    11  
    12  env:
    13    GITHUB_OWNER: mysteriumnetwork
    14    GITHUB_REPO: node
    15    GITHUB_SNAPSHOT_REPO: node-builds
    16    GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    17    AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
    18    AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
    19    AWS_EC2_METADATA_DISABLED: true # disable AWS region lookup
    20  
    21  jobs:
    22    setup-env:
    23      runs-on: ubuntu-latest
    24  
    25      steps:
    26        - uses: actions/checkout@v4
    27          with:
    28            fetch-depth: 0
    29            fetch-tags: true
    30        - name: Setup Go
    31          uses: actions/setup-go@v5
    32          with:
    33            go-version: '1.21.x'
    34  
    35        - name: Prepare environment 
    36          run: |
    37            RELEASE_BUILD=false
    38            if [[ "${GITHUB_REF}" == refs/tags/* ]]; then RELEASE_BUILD=true; fi
    39            
    40            RC_BUILD=false
    41            if [[ "${GITHUB_REF}" == refs/tags/*-rc* ]]; then RC_BUILD=true; fi
    42  
    43            SNAPSHOT_BUILD=false
    44            if [[ "${GITHUB_REF}" == "refs/heads/master" ]]; then SNAPSHOT_BUILD=true; fi
    45  
    46            PR_BUILD=false
    47            if [[ "${SNAPSHOT_BUILD}" == "false" && "${RELEASE_BUILD}" == "false" ]]; then PR_BUILD=true; fi
    48  
    49            if [[ "${RELEASE_BUILD}" == "true" ]]; then 
    50              BUILD_VERSION="${GITHUB_REF#refs/tags/}";
    51            elif [[ "${SNAPSHOT_BUILD}" == "true" ]]; then
    52              BUILD_VERSION="$(git describe --abbrev=0 --tags)"-1snapshot-"$(date '+%Y%m%dT%H%M')"-"$(echo ${GITHUB_SHA} | cut -c1-8)"; 
    53            elif [[ "${PR_BUILD}" == "true" ]]; then 
    54              BRANCH="${GITHUB_HEAD_REF////-}"
    55              if [[ "${BRANCH}" == "" ]]; then BRANCH="${GITHUB_REF_NAME}"; fi
    56              BUILD_VERSION="$(git describe --abbrev=0 --tags)"-1branch-"${BRANCH}";
    57            fi
    58  
    59            cat <<EOT >> env.sh
    60            export RELEASE_BUILD=$RELEASE_BUILD;
    61            export RC_BUILD=$RC_BUILD;
    62            export PR_BUILD=$PR_BUILD;
    63            export SNAPSHOT_BUILD=$SNAPSHOT_BUILD;
    64            export BUILD_VERSION=$BUILD_VERSION;
    65            export BUILD_NUMBER="${{ github.run_id }}";
    66            export BUILD_COMMIT="$(echo ${GITHUB_SHA} | cut -c1-8)";
    67            export BUILD_BRANCH="${GITHUB_REF_NAME}";
    68            EOT
    69  
    70        - uses: actions/upload-artifact@v4
    71          with:
    72            name: env.sh
    73            path: env.sh
    74  
    75        - name: Create bucket
    76          if: |
    77            github.ref == 'refs/heads/master' ||
    78            github.ref_type == 'tag'
    79          run: |
    80            source env.sh
    81            go run mage.go -v MakeBucket
    82  
    83    build-packages:
    84      runs-on: ubuntu-latest
    85      needs: [setup-env]
    86  
    87      strategy:
    88        max-parallel: 6
    89        matrix:
    90          platform:
    91            - PackageLinuxRaspberryImage
    92            - PackageLinuxAmd64
    93            - PackageLinuxArm
    94            - PackageLinuxDebianAmd64
    95            - PackageLinuxDebianArm64
    96            - PackageLinuxDebianArmv6l
    97            - PackageLinuxDebianArm
    98            - PackageMacOSAmd64
    99            - PackageMacOSArm64
   100            - PackageWindowsAmd64
   101            - PackageAndroid
   102            - PackageAndroidProvider
   103  
   104      steps:
   105        - uses: actions/checkout@v4
   106        - name: Setup Go
   107          uses: actions/setup-go@v5
   108          with:
   109            go-version: '1.21.x'
   110        - uses: actions/download-artifact@v4
   111          with:
   112            name: env.sh
   113  
   114        - name: Setup FPM
   115          run: |
   116            sudo apt-get update
   117            sudo apt-get install ruby-dev build-essential
   118            sudo gem i fpm -f
   119        
   120        - name: Build package
   121          run: |
   122            source env.sh
   123            unset CI # workaround for "PackageAndroid" target
   124            sudo -E go run mage.go -v ${{ matrix.platform }}
   125  
   126    build-swagger:
   127      runs-on: ubuntu-latest
   128      needs: [setup-env, build-packages]
   129  
   130      steps:
   131        - uses: actions/checkout@v4
   132        - name: Setup Go
   133          uses: actions/setup-go@v5
   134          with:
   135            go-version: '1.21.x'
   136        - uses: actions/download-artifact@v4
   137          with:
   138            name: env.sh
   139        - name: Login to Docker Hub
   140          uses: docker/login-action@v3
   141          with:
   142             username: ${{ secrets.DOCKERHUB_USERNAME }}
   143             password: ${{ secrets.DOCKERHUB_PASSWORD }}
   144        - name: Set up Docker Buildx
   145          uses: docker/setup-buildx-action@v3
   146  
   147        - name: Build docker
   148          run: |
   149            source env.sh
   150            go run mage.go -v PackageDockerSwaggerRedoc
   151  
   152    release:
   153      needs: [build-packages, build-swagger]
   154      uses: ./.github/workflows/release.yml
   155      secrets: inherit
   156      if: |
   157        github.ref == 'refs/heads/master' ||
   158        github.ref_type == 'tag'
   159  
   160    cleanup-env:
   161      runs-on: ubuntu-latest
   162      needs: [release]
   163      if: |
   164        always() &&
   165        (github.ref == 'refs/heads/master' || github.ref_type == 'tag')
   166  
   167      steps:
   168        - uses: actions/checkout@v4
   169        - name: Setup Go
   170          uses: actions/setup-go@v5
   171          with:
   172            go-version: '1.21.x'
   173        - uses: actions/download-artifact@v4
   174          with:
   175            name: env.sh
   176  
   177        - name: Remove bucket
   178          run: |
   179            source env.sh
   180            go run mage.go -v RemoveBucket || true # ignore if bucket was not available