|
| 1 | +name: Create Staging Release |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + inputs: |
| 5 | + PLUGIN_NAME: |
| 6 | + description: 'Plugin to build and tag. The name must match the plugin directory name in GitHub.' |
| 7 | + required: false |
| 8 | + pull_request: |
| 9 | + types: [closed] |
| 10 | + branches: |
| 11 | + - develop |
| 12 | + |
| 13 | +env: |
| 14 | + PACKAGECLOUD_PYTHON_TOOLING_STABLE: ${{ secrets.PACKAGECLOUD_PYTHON_TOOLING_STABLE }} |
| 15 | + |
| 16 | +permissions: |
| 17 | + contents: write |
| 18 | + actions: read |
| 19 | + |
| 20 | +jobs: |
| 21 | + release: |
| 22 | + runs-on: ubuntu-latest |
| 23 | + |
| 24 | + steps: |
| 25 | + - name: Check if merged |
| 26 | + id: checkIfMerged |
| 27 | + run: | |
| 28 | + echo "INSIGHT_KOMAND_BRANCH=develop" >> $GITHUB_ENV |
| 29 | + if [[ "${{ github.event.pull_request.merged }}" == "true" ]]; then |
| 30 | + echo "Pull requst has been merged. Starting release process..." |
| 31 | + echo "ROOT_BUILD_CAUSE=SCMTRIGGER" >> $GITHUB_ENV |
| 32 | + elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then |
| 33 | + echo "Workflow was manually triggered. Starting release process..." |
| 34 | + echo "ROOT_BUILD_CAUSE=MANUALTRIGGER" >> $GITHUB_ENV |
| 35 | + echo "INSIGHT_KOMAND_PLUGIN_NAME=${{ github.event.inputs.PLUGIN_NAME || '' }}" >> $GITHUB_ENV |
| 36 | + else |
| 37 | + echo "Pull request has not been merged. Stopping workflow..." |
| 38 | + exit 1 |
| 39 | + fi |
| 40 | +
|
| 41 | + - name: Checkout Repository |
| 42 | + id: checkoutRepository |
| 43 | + uses: actions/checkout@v3 |
| 44 | + with: |
| 45 | + fetch-depth: 5 |
| 46 | + ref: "refs/heads/${{ env.INSIGHT_KOMAND_BRANCH }}" |
| 47 | + |
| 48 | + - name: Setup Python |
| 49 | + id: setupPython |
| 50 | + uses: actions/setup-python@v4 |
| 51 | + with: |
| 52 | + python-version: '3.8' |
| 53 | + |
| 54 | + - name: Setup venv |
| 55 | + id: setUpVenv |
| 56 | + run: | |
| 57 | + python3 -m venv .ci_venv |
| 58 | + source .ci_venv/bin/activate |
| 59 | + pip install --upgrade pip |
| 60 | +
|
| 61 | + - name: Set up environment variables |
| 62 | + id: setUpEnvironmentVariables |
| 63 | + run: | |
| 64 | + # Setup environment variables from input |
| 65 | + echo "BUILD_OUTPUT_DIRECTORY=builds" >> $GITHUB_ENV |
| 66 | + echo "BUILD_OUTPUT_FULL_PATH=plugins/builds" >> $GITHUB_ENV |
| 67 | +
|
| 68 | + - name: Prerelease Timestamp |
| 69 | + id: prereleaseTimestamp |
| 70 | + run: | |
| 71 | + TIMESTAMP=$(date +%s%1N | cut -b1-10) |
| 72 | + echo "PRERELEASE=true" >> $GITHUB_ENV |
| 73 | + echo "PRERELEASE_TIMESTAMP=$TIMESTAMP" >> $GITHUB_ENV |
| 74 | +
|
| 75 | + - name: Install CI/CD Tool |
| 76 | + id: installCICDTool |
| 77 | + run: | |
| 78 | + # Install CI Tooling |
| 79 | + curl -s https://${PACKAGECLOUD_PYTHON_TOOLING_STABLE}:@packagecloud.io/install/repositories/rapid7/insightconnect_internal_python_tooling/script.python.sh | bash |
| 80 | + .ci_venv/bin/pip install icon-integrations-ci~=3.0 |
| 81 | +
|
| 82 | + - name: Build Plugin Image |
| 83 | + id: buildPluginImage |
| 84 | + if: success() |
| 85 | + run: | |
| 86 | + cd plugins |
| 87 | + ../.ci_venv/bin/icon-ci build -d ${{ env.BUILD_OUTPUT_DIRECTORY }} |
| 88 | +
|
| 89 | + - name: Find Release Asset |
| 90 | + id: findReleaseAsset |
| 91 | + run: | |
| 92 | + # Navigate to the build directory |
| 93 | + cd ${{ env.BUILD_OUTPUT_FULL_PATH }} |
| 94 | + # Use find to get the filename |
| 95 | + filename=$(find . -type f -maxdepth 1 | xargs basename) |
| 96 | + echo "RELEASE_ASSET=${filename}" >> $GITHUB_ENV |
| 97 | + echo "GIT_TAG=${filename%.tar.gz}" >> $GITHUB_ENV |
| 98 | +
|
| 99 | + - name: Create release |
| 100 | + id: createRelease |
| 101 | + uses: actions/create-release@v1 |
| 102 | + env: |
| 103 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 104 | + with: |
| 105 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 106 | + tag_name: ${{ env.GIT_TAG }} |
| 107 | + release_name: ${{ env.GIT_TAG }} |
| 108 | + body: | |
| 109 | + ${{ env.GIT_TAG }} |
| 110 | + draft: false |
| 111 | + prerelease: false |
| 112 | + |
| 113 | + - name: Upload release asset |
| 114 | + id: uploadReleaseAsset |
| 115 | + uses: actions/upload-release-asset@v1 |
| 116 | + env: |
| 117 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 118 | + with: |
| 119 | + upload_url: ${{ steps.createRelease.outputs.upload_url }} |
| 120 | + asset_path: ${{ env.BUILD_OUTPUT_FULL_PATH }}/${{ env.RELEASE_ASSET }} |
| 121 | + asset_name: ${{ env.RELEASE_ASSET }} |
| 122 | + asset_content_type: application/gzip |
0 commit comments