|
| 1 | +name: Build |
| 2 | + |
| 3 | +description: > |
| 4 | + Creates the UCC build for the addon, generates the SPL file using slim |
| 5 | + and uploads it to the Github registry |
| 6 | +
|
| 7 | +inputs: |
| 8 | + python_version: |
| 9 | + required: true |
| 10 | + SA_GH_USER_NAME: |
| 11 | + required: true |
| 12 | + SA_GH_USER_EMAIL: |
| 13 | + required: true |
| 14 | + SA_GPG_PRIVATE_KEY: |
| 15 | + required: true |
| 16 | + SA_GPG_PASSPHRASE: |
| 17 | + required: true |
| 18 | + AWS_ACCESS_KEY_ID: |
| 19 | + required: true |
| 20 | + AWS_DEFAULT_REGION: |
| 21 | + required: true |
| 22 | + AWS_SECRET_ACCESS_KEY: |
| 23 | + required: true |
| 24 | + ucc_modinput_functional: |
| 25 | + required: true |
| 26 | + modinput_functional: |
| 27 | + required: true |
| 28 | + |
| 29 | +outputs: |
| 30 | + buildname: |
| 31 | + value: ${{ steps.buildupload.outputs.name }} |
| 32 | + |
| 33 | +runs: |
| 34 | + using: composite |
| 35 | + steps: |
| 36 | + - name: Checkout repository |
| 37 | + uses: actions/checkout@v3 |
| 38 | + with: |
| 39 | + # Very Important: semantic-release won't trigger a tagged |
| 40 | + # build if this is not set to false |
| 41 | + persist-credentials: false |
| 42 | + |
| 43 | + - name: Setup python |
| 44 | + uses: actions/setup-python@v4 |
| 45 | + with: |
| 46 | + python-version: 3.7 |
| 47 | + |
| 48 | + - name: Create requirements file for pip |
| 49 | + shell: bash |
| 50 | + run: | |
| 51 | + if [ -f "poetry.lock" ] |
| 52 | + then |
| 53 | + echo " poetry.lock found " |
| 54 | + sudo pip3 install poetry==1.5.1 poetry-plugin-export==1.4.0 |
| 55 | + poetry lock --check |
| 56 | + poetry export --without-hashes -o requirements.txt |
| 57 | + if [ "$(grep -cve '^\s*$' requirements.txt)" -ne 0 ] |
| 58 | + then |
| 59 | + echo "Prod dependencies were found, creating package/lib folder" |
| 60 | + mkdir -p package/lib || true |
| 61 | + mv requirements.txt package/lib |
| 62 | + else |
| 63 | + echo "No prod dependencies were found" |
| 64 | + rm requirements.txt |
| 65 | + fi |
| 66 | + poetry export --without-hashes --dev -o requirements_dev.txt |
| 67 | + cat requirements_dev.txt |
| 68 | + fi |
| 69 | +
|
| 70 | + - name: Get pip cache dir |
| 71 | + id: pip-cache |
| 72 | + shell: bash |
| 73 | + run: | |
| 74 | + echo "dir=$(pip cache dir)" >> "$GITHUB_OUTPUT" |
| 75 | +
|
| 76 | + - name: Run Check there are libraries to scan |
| 77 | + id: checklibs |
| 78 | + shell: bash |
| 79 | + run: if [ -f requirements_dev.txt ]; then echo "ENABLED=true" >> "$GITHUB_OUTPUT"; fi |
| 80 | + |
| 81 | + - name: Run pip cache |
| 82 | + if: ${{ steps.checklibs.outputs.ENABLED == 'true' }} |
| 83 | + uses: actions/cache@v3 |
| 84 | + with: |
| 85 | + path: ${{ steps.pip-cache.outputs.dir }} |
| 86 | + key: ${{ runner.os }}-pip-${{ hashFiles('requirements_dev.txt') }} |
| 87 | + restore-keys: | |
| 88 | + ${{ runner.os }}-pip- |
| 89 | +
|
| 90 | + - name: Install deps |
| 91 | + if: ${{ steps.checklibs.outputs.ENABLED == 'true' }} |
| 92 | + shell: bash |
| 93 | + run: pip install -r requirements_dev.txt |
| 94 | + |
| 95 | + - name: Semantic Release Get Next |
| 96 | + id: semantic |
| 97 | + if: github.event_name != 'pull_request' |
| 98 | + |
| 99 | + with: |
| 100 | + dry_run: true |
| 101 | + git_committer_name: ${{ inputs.SA_GH_USER_NAME }} |
| 102 | + git_committer_email: ${{ inputs.SA_GH_USER_EMAIL }} |
| 103 | + gpg_private_key: ${{ inputs.SA_GPG_PRIVATE_KEY }} |
| 104 | + passphrase: ${{ inputs.SA_GPG_PASSPHRASE }} |
| 105 | + env: |
| 106 | + GITHUB_TOKEN: ${{ github.token }} |
| 107 | + |
| 108 | + - name: Determine the version to build |
| 109 | + id: BuildVersion |
| 110 | + uses: splunk/addonfactory-get-splunk-package-version-action@v1 |
| 111 | + with: |
| 112 | + SemVer: ${{ steps.semantic.outputs.new_release_version }} |
| 113 | + PrNumber: ${{ github.event.number }} |
| 114 | + |
| 115 | + - name: Download THIRDPARTY |
| 116 | + if: ${{ inputs.python_version }} == '3.7' && github.event_name != 'pull_request' && github.event_name != 'schedule' |
| 117 | + uses: actions/download-artifact@v3 |
| 118 | + with: |
| 119 | + name: THIRDPARTY |
| 120 | + |
| 121 | + - name: Download THIRDPARTY (Optional for PR and schedule) |
| 122 | + if: ${{ inputs.python_version }} == '3.7' && github.event_name == 'pull_request' || github.event_name == 'schedule' |
| 123 | + continue-on-error: true |
| 124 | + uses: actions/download-artifact@v3 |
| 125 | + with: |
| 126 | + name: THIRDPARTY |
| 127 | + |
| 128 | + - name: Update Notices |
| 129 | + if: ${{ inputs.python_version }} == '3.7' |
| 130 | + shell: bash |
| 131 | + run: | |
| 132 | + cp -f THIRDPARTY package/THIRDPARTY || echo "THIRDPARTY file not found (allowed for PR and schedule)" |
| 133 | +
|
| 134 | + - name: Build Package |
| 135 | + id: uccgen |
| 136 | + uses: splunk/addonfactory-ucc-generator-action@v2 |
| 137 | + with: |
| 138 | + version: ${{ steps.BuildVersion.outputs.VERSION }} |
| 139 | + |
| 140 | + - name: Slim Package |
| 141 | + if: always() && ${{ inputs.python_version }} == '3.7' |
| 142 | + id: slim |
| 143 | + uses: splunk/addonfactory-packaging-toolkit-action@v1 |
| 144 | + with: |
| 145 | + source: ${{ steps.uccgen.outputs.OUTPUT }} |
| 146 | + |
| 147 | + - name: Artifact OpenAPI |
| 148 | + if: ${{ inputs.python_version }} == '3.7' && ${{ !cancelled() && inputs.ucc_modinput_functional == 'true' && inputs.modinput_functional == 'true' }} |
| 149 | + uses: actions/upload-artifact@v3 |
| 150 | + with: |
| 151 | + name: artifact-openapi |
| 152 | + path: ${{ github.workspace }}/${{ steps.uccgen.outputs.OUTPUT }}/static/openapi.json |
| 153 | + |
| 154 | + - name: Artifact Splunkbase |
| 155 | + if: ${{ !cancelled() }} && ${{ inputs.python_version }} == '3.7' |
| 156 | + uses: actions/upload-artifact@v3 |
| 157 | + with: |
| 158 | + name: package-splunkbase |
| 159 | + path: ${{ steps.slim.outputs.OUTPUT }} |
| 160 | + |
| 161 | + - name: Upload build to S3 |
| 162 | + if: ${{ inputs.python_version }} == '3.7' |
| 163 | + id: buildupload |
| 164 | + shell: bash |
| 165 | + env: |
| 166 | + AWS_ACCESS_KEY_ID: ${{ inputs.AWS_ACCESS_KEY_ID }} |
| 167 | + AWS_DEFAULT_REGION: ${{ inputs.AWS_DEFAULT_REGION }} |
| 168 | + AWS_SECRET_ACCESS_KEY: ${{ inputs.AWS_SECRET_ACCESS_KEY }} |
| 169 | + run: | |
| 170 | + echo "name=$(basename "${{ steps.slim.outputs.OUTPUT }}")" >> "$GITHUB_OUTPUT" |
| 171 | + basename "${{ steps.slim.outputs.OUTPUT }}" |
| 172 | + aws s3 cp "${{ steps.slim.outputs.OUTPUT }}" s3://ta-production-artifacts/ta-apps/ |
| 173 | + |
| 174 | + - name: Artifact Splunk parts |
| 175 | + if: ${{ !cancelled() }} && ${{ inputs.python_version }} == '3.7' |
| 176 | + uses: actions/upload-artifact@v3 |
| 177 | + with: |
| 178 | + name: package-deployment |
| 179 | + path: build/package/deployment** |
0 commit comments