|
| 1 | +name: publish-untested |
| 2 | +on: |
| 3 | + workflow_call: |
| 4 | + secrets: |
| 5 | + GH_TOKEN_ADMIN: |
| 6 | + description: Github admin token |
| 7 | + required: true |
| 8 | + GITHUB_TOKEN: |
| 9 | + description: Github token |
| 10 | + required: true |
| 11 | + |
| 12 | +jobs: |
| 13 | + validate_branch: |
| 14 | + name: validate_branch |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: validate_branch |
| 18 | + if: github.ref != 'refs/heads/develop' && github.ref != 'refs/heads/main' |
| 19 | + run: | |
| 20 | + echo "Skipping publish as branch is neither main nor develop" |
| 21 | + build: |
| 22 | + needs: |
| 23 | + - validate_branch |
| 24 | + if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' |
| 25 | + name: build |
| 26 | + runs-on: ubuntu-latest |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@v2 |
| 29 | + with: |
| 30 | + # Very Important semantic-release won't trigger a tagged |
| 31 | + # build if this is not set false |
| 32 | + persist-credentials: false |
| 33 | + - name: Setup python |
| 34 | + uses: actions/setup-python@v2 |
| 35 | + with: |
| 36 | + python-version: 3.7 |
| 37 | + - uses: actions/setup-node@v2 |
| 38 | + with: |
| 39 | + node-version: 14 |
| 40 | + - name: create requirements file for pip |
| 41 | + run: | |
| 42 | + if [ -f "poetry.lock" ] |
| 43 | + then |
| 44 | + echo " potery.lock found " |
| 45 | + sudo pip3 install poetry |
| 46 | + mkdir -p package/lib || true |
| 47 | + poetry export --without-hashes -o package/lib/requirements.txt |
| 48 | + poetry export --without-hashes --dev -o requirements_dev.txt |
| 49 | + cat requirements_dev.txt |
| 50 | + fi |
| 51 | + - name: Get pip cache dir |
| 52 | + id: pip-cache |
| 53 | + run: | |
| 54 | + echo "::set-output name=dir::$(pip cache dir)" |
| 55 | + - name: Run Check there are libraries to scan |
| 56 | + id: checklibs |
| 57 | + run: if [ -f requirements_dev.txt ]; then echo "::set-output name=ENABLED::true"; fi |
| 58 | + - name: pip cache |
| 59 | + if: ${{ steps.checklibs.outputs.ENABLED == 'true' }} |
| 60 | + uses: actions/cache@v2 |
| 61 | + with: |
| 62 | + path: ${{ steps.pip-cache.outputs.dir }} |
| 63 | + key: ${{ runner.os }}-pip-${{ hashFiles('requirements_dev.txt') }} |
| 64 | + restore-keys: | |
| 65 | + ${{ runner.os }}-pip- |
| 66 | + - name: Install deps |
| 67 | + if: ${{ steps.checklibs.outputs.ENABLED == 'true' }} |
| 68 | + run: pip install -r requirements_dev.txt |
| 69 | + - name: Determine the version to build |
| 70 | + id: BuildVersion |
| 71 | + uses: splunk/addonfactory-get-splunk-package-version-action@v1 |
| 72 | + with: |
| 73 | + SemVer: ${{ github.event.inputs.tag }} |
| 74 | + PrNumber: ${{ github.event.number }} |
| 75 | + - name: Build Package |
| 76 | + id: uccgen |
| 77 | + uses: splunk/addonfactory-ucc-generator-action@v1 |
| 78 | + with: |
| 79 | + version: ${{ steps.BuildVersion.outputs.VERSION }} |
| 80 | + - name: Slim Package |
| 81 | + id: slim |
| 82 | + uses: splunk/addonfactory-packaging-toolkit-action@v1 |
| 83 | + with: |
| 84 | + source: ${{ steps.uccgen.outputs.OUTPUT }} |
| 85 | + - name: artifact-splunk-unpacked |
| 86 | + uses: actions/upload-artifact@v2 |
| 87 | + with: |
| 88 | + name: package-raw |
| 89 | + path: ${{ steps.uccgen.outputs.OUTPUT }}** |
| 90 | + if: always() |
| 91 | + - name: artifact-splunk-base |
| 92 | + uses: actions/upload-artifact@v2 |
| 93 | + with: |
| 94 | + name: package-splunkbase |
| 95 | + path: ${{ steps.slim.outputs.OUTPUT }} |
| 96 | + if: always() |
| 97 | + - name: artifact-splunk-parts |
| 98 | + uses: actions/upload-artifact@v2 |
| 99 | + with: |
| 100 | + name: package-deployment |
| 101 | + path: build/package/deployment** |
| 102 | + if: always() |
| 103 | + |
| 104 | + publish: |
| 105 | + needs: |
| 106 | + - build |
| 107 | + - validate_branch |
| 108 | + if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' |
| 109 | + runs-on: ubuntu-latest |
| 110 | + steps: |
| 111 | + - name: Checkout |
| 112 | + uses: actions/checkout@v2 |
| 113 | + with: |
| 114 | + submodules: false |
| 115 | + persist-credentials: false |
| 116 | + - name: Release on github |
| 117 | + if: github.ref == 'refs/heads/main' |
| 118 | + uses: "marvinpinto/action-automatic-releases@latest" |
| 119 | + with: |
| 120 | + repo_token: "${{ secrets.GITHUB_TOKEN }}" |
| 121 | + prerelease: false |
| 122 | + automatic_release_tag: v${{ github.event.inputs.tag }} |
| 123 | + - name: Release on github (pre-release) |
| 124 | + if: github.ref == 'refs/heads/develop' |
| 125 | + uses: "marvinpinto/action-automatic-releases@latest" |
| 126 | + with: |
| 127 | + repo_token: "${{ secrets.GITHUB_TOKEN }}" |
| 128 | + prerelease: true |
| 129 | + automatic_release_tag: v${{ github.event.inputs.tag }} |
| 130 | + - name: Download package-deployment |
| 131 | + uses: actions/download-artifact@v2 |
| 132 | + id: download-package-deployment |
| 133 | + with: |
| 134 | + name: package-deployment |
| 135 | + path: download/artifacts/ |
| 136 | + - name: Download package-splunkbase |
| 137 | + uses: actions/download-artifact@v2 |
| 138 | + id: download-package-splunkbase |
| 139 | + with: |
| 140 | + name: package-splunkbase |
| 141 | + path: download/artifacts/deployment |
| 142 | + - name: List of assets |
| 143 | + run: | |
| 144 | + ls -la ${{ steps.download-package-splunkbase.outputs.download-path }} |
| 145 | + - name: Upload assets to release |
| 146 | + uses: svenstaro/upload-release-action@v2 |
| 147 | + with: |
| 148 | + repo_token: ${{ secrets.GH_TOKEN_ADMIN }} |
| 149 | + file: ${{ steps.download-package-splunkbase.outputs.download-path }}/* |
| 150 | + overwrite: true |
| 151 | + file_glob: true |
| 152 | + tag: v${{ github.event.inputs.tag }} |
0 commit comments