|
| 1 | +# GitHub Actions Workflow created for testing and preparing the plugin release in following steps: |
| 2 | +# - validate Gradle Wrapper, |
| 3 | +# - run test and verifyPlugin tasks, |
| 4 | +# - run buildPlugin task and prepare artifact for the further tests, |
| 5 | +# - run IntelliJ Plugin Verifier, |
| 6 | +# - create a draft release. |
| 7 | +# |
| 8 | +# Workflow is triggered on push and pull_request events. |
| 9 | +# |
| 10 | +# Docs: |
| 11 | +# - GitHub Actions: https://help.github.com/en/actions |
| 12 | +# - IntelliJ Plugin Verifier GitHub Action: https://github.com/ChrisCarini/intellij-platform-plugin-verifier-action |
| 13 | +# |
| 14 | +## JBIJPPTPL |
| 15 | + |
| 16 | +name: Build |
| 17 | +on: [push, pull_request] |
| 18 | +jobs: |
| 19 | + |
| 20 | + # Run Gradle Wrapper Validation Action to verify the wrapper's checksum |
| 21 | + gradleValidation: |
| 22 | + name: Gradle Wrapper |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + |
| 26 | + # Check out current repository |
| 27 | + - name: Fetch Sources |
| 28 | + uses: actions/checkout@v2 |
| 29 | + with: |
| 30 | + submodules: true |
| 31 | + |
| 32 | + # Validate wrapper |
| 33 | + - name: Gradle Wrapper Validation |
| 34 | + uses: gradle/wrapper-validation-action@v1 |
| 35 | + |
| 36 | + # Run verifyPlugin and test Gradle tasks |
| 37 | + test: |
| 38 | + name: Test |
| 39 | + needs: gradleValidation |
| 40 | + runs-on: ubuntu-latest |
| 41 | + steps: |
| 42 | + |
| 43 | + # Setup Java 1.8 environment for the next steps |
| 44 | + - name: Setup Java |
| 45 | + uses: actions/setup-java@v1 |
| 46 | + with: |
| 47 | + java-version: 1.8 |
| 48 | + |
| 49 | + # Check out current repository |
| 50 | + - name: Fetch Sources |
| 51 | + uses: actions/checkout@v2 |
| 52 | + with: |
| 53 | + submodules: true |
| 54 | + |
| 55 | + # Cache Gradle dependencies |
| 56 | + - name: Setup Gradle Dependencies Cache |
| 57 | + uses: actions/cache@v2 |
| 58 | + with: |
| 59 | + path: ~/.gradle/caches |
| 60 | + key: ${{ runner.os }}-gradle-caches-${{ hashFiles('**/*.gradle', '**/*.gradle.kts', 'gradle.properties') }} |
| 61 | + |
| 62 | + # Cache Gradle Wrapper |
| 63 | + - name: Setup Gradle Wrapper Cache |
| 64 | + uses: actions/cache@v2 |
| 65 | + with: |
| 66 | + path: ~/.gradle/wrapper |
| 67 | + key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }} |
| 68 | + |
| 69 | + # Run detekt, ktlint and tests |
| 70 | + #- name: Run Linters and Test |
| 71 | + # run: ./gradlew check |
| 72 | + |
| 73 | + # Run verifyPlugin Gradle task |
| 74 | + - name: Verify Plugin |
| 75 | + run: ./gradlew verifyPlugin |
| 76 | + |
| 77 | + # Build plugin with buildPlugin Gradle task and provide the artifact for the next workflow jobs |
| 78 | + # Requires test job to be passed |
| 79 | + build: |
| 80 | + name: Build |
| 81 | + needs: test |
| 82 | + runs-on: ubuntu-latest |
| 83 | + outputs: |
| 84 | + name: ${{ steps.properties.outputs.name }} |
| 85 | + version: ${{ steps.properties.outputs.version }} |
| 86 | + changelog: ${{ steps.properties.outputs.changelog }} |
| 87 | + artifact: ${{ steps.properties.outputs.artifact }} |
| 88 | + steps: |
| 89 | + |
| 90 | + # Setup Java 1.8 environment for the next steps |
| 91 | + - name: Setup Java |
| 92 | + uses: actions/setup-java@v1 |
| 93 | + with: |
| 94 | + java-version: 1.8 |
| 95 | + |
| 96 | + # Check out current repository |
| 97 | + - name: Fetch Sources |
| 98 | + uses: actions/checkout@v2 |
| 99 | + with: |
| 100 | + submodules: true |
| 101 | + |
| 102 | + # Cache Gradle Dependencies |
| 103 | + - name: Setup Gradle Dependencies Cache |
| 104 | + uses: actions/cache@v2 |
| 105 | + with: |
| 106 | + path: ~/.gradle/caches |
| 107 | + key: ${{ runner.os }}-gradle-caches-${{ hashFiles('**/*.gradle', '**/*.gradle.kts', 'gradle.properties') }} |
| 108 | + |
| 109 | + # Cache Gradle Wrapper |
| 110 | + - name: Setup Gradle Wrapper Cache |
| 111 | + uses: actions/cache@v2 |
| 112 | + with: |
| 113 | + path: ~/.gradle/wrapper |
| 114 | + key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }} |
| 115 | + |
| 116 | + # Set environment variables |
| 117 | + - name: Export Properties |
| 118 | + id: properties |
| 119 | + shell: bash |
| 120 | + run: | |
| 121 | + PROPERTIES="$(./gradlew properties --console=plain -q)" |
| 122 | + VERSION="$(echo "$PROPERTIES" | grep "^version:" | cut -f2- -d ' ')" |
| 123 | + NAME="$(echo "$PROPERTIES" | grep "^pluginName_:" | cut -f2- -d ' ')" |
| 124 | + CHANGELOG="$(./gradlew getChangelog --unreleased --no-header --console=plain -q)" |
| 125 | + CHANGELOG="${CHANGELOG//'%'/'%25'}" |
| 126 | + CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" |
| 127 | + CHANGELOG="${CHANGELOG//$'\r'/'%0D'}" |
| 128 | + ARTIFACT="${NAME}-${VERSION}.zip" |
| 129 | +
|
| 130 | + echo "::set-output name=version::$VERSION" |
| 131 | + echo "::set-output name=name::$NAME" |
| 132 | + echo "::set-output name=changelog::$CHANGELOG" |
| 133 | + echo "::set-output name=artifact::$ARTIFACT" |
| 134 | +
|
| 135 | + # Build artifact using buildPlugin Gradle task |
| 136 | + - name: Build Plugin |
| 137 | + run: ./gradlew buildPlugin |
| 138 | + |
| 139 | + # Upload plugin artifact to make it available in the next jobs |
| 140 | + - name: Upload artifact |
| 141 | + uses: actions/upload-artifact@v1 |
| 142 | + with: |
| 143 | + name: plugin-artifact |
| 144 | + path: ./build/distributions/${{ needs.build.outputs.artifact }} |
| 145 | + |
| 146 | + # Verify built plugin using IntelliJ Plugin Verifier tool |
| 147 | + # Requires build job to be passed |
| 148 | + verify: |
| 149 | + name: Verify |
| 150 | + needs: build |
| 151 | + runs-on: ubuntu-latest |
| 152 | + steps: |
| 153 | + |
| 154 | + # Download plugin artifact provided by the previous job |
| 155 | + - name: Download Artifact |
| 156 | + uses: actions/download-artifact@v1 |
| 157 | + with: |
| 158 | + name: plugin-artifact |
| 159 | + |
| 160 | + # Run IntelliJ Plugin Verifier action using GitHub Action |
| 161 | + - name: Verify Plugin |
| 162 | + id: verify |
| 163 | + uses: ChrisCarini/[email protected] |
| 164 | + with: |
| 165 | + plugin-location: plugin-artifact/*.zip |
| 166 | + ide-versions: | |
| 167 | + ideaIC:2020.1 |
| 168 | + ideaIC:2020.2 |
| 169 | +
|
| 170 | + # Print the output of the verify step |
| 171 | + - name: Print Logs |
| 172 | + if: ${{ always() }} |
| 173 | + env: |
| 174 | + OUTPUT_LOG: ${{ steps.verify.outputs.verification-output-log-filename }} |
| 175 | + run: | |
| 176 | + echo "The verifier log file [$OUTPUT_LOG] contents : " ; |
| 177 | + cat $OUTPUT_LOG |
| 178 | +
|
| 179 | + # Prepare a draft release for GitHub Releases page for the manual verification |
| 180 | + # If accepted and published, release workflow would be triggered |
| 181 | + releaseDraft: |
| 182 | + name: Release Draft |
| 183 | + if: github.event_name != 'pull_request' |
| 184 | + needs: [build, verify] |
| 185 | + runs-on: ubuntu-latest |
| 186 | + steps: |
| 187 | + |
| 188 | + # Check out current repository |
| 189 | + - name: Fetch Sources |
| 190 | + uses: actions/checkout@v2 |
| 191 | + with: |
| 192 | + submodules: true |
| 193 | + |
| 194 | + # Remove old release drafts by using the curl request for the available releases with draft flag |
| 195 | + - name: Remove Old Release Drafts |
| 196 | + env: |
| 197 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 198 | + run: | |
| 199 | + curl -H "Authorization: Bearer $GITHUB_TOKEN" https://api.github.com/repos/$GITHUB_REPOSITORY/releases \ |
| 200 | + | tr '\r\n' ' ' \ |
| 201 | + | jq '.[] | select(.draft == true) | .id' \ |
| 202 | + | xargs -I '{}' \ |
| 203 | + curl -X DELETE -H "Authorization: Bearer $GITHUB_TOKEN" https://api.github.com/repos/$GITHUB_REPOSITORY/releases/{} |
| 204 | +
|
| 205 | + # Create new release draft - which is not publicly visible and requires manual acceptance |
| 206 | + - name: Create Release Draft |
| 207 | + id: createDraft |
| 208 | + uses: actions/create-release@v1 |
| 209 | + env: |
| 210 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 211 | + with: |
| 212 | + tag_name: v${{ needs.build.outputs.version }} |
| 213 | + release_name: v${{ needs.build.outputs.version }} |
| 214 | + body: ${{ needs.build.outputs.changelog }} |
| 215 | + draft: true |
| 216 | + |
| 217 | + # Download plugin artifact provided by the previous job |
| 218 | + - name: Download Artifact |
| 219 | + uses: actions/download-artifact@v1 |
| 220 | + with: |
| 221 | + name: plugin-artifact |
| 222 | + |
| 223 | + # Upload artifact as a release asset |
| 224 | + - name: Upload Release Asset |
| 225 | + id: upload-release-asset |
| 226 | + uses: actions/upload-release-asset@v1 |
| 227 | + env: |
| 228 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 229 | + with: |
| 230 | + upload_url: ${{ steps.createDraft.outputs.upload_url }} |
| 231 | + asset_path: ./plugin-artifact/${{ needs.build.outputs.artifact }} |
| 232 | + asset_name: ${{ needs.build.outputs.artifact }} |
| 233 | + asset_content_type: application/zip |
0 commit comments