|
| 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: |
| 18 | + # Trigger the workflow on pushes to only the 'main' branch (this avoids duplicate checks being run e.g. for dependabot pull requests) |
| 19 | + push: |
| 20 | + branches: [main] |
| 21 | + # Trigger the workflow on any pull request |
| 22 | + pull_request: |
| 23 | + |
| 24 | +jobs: |
| 25 | + |
| 26 | + # Run Gradle Wrapper Validation Action to verify the wrapper's checksum |
| 27 | + gradleValidation: |
| 28 | + name: Gradle Wrapper |
| 29 | + runs-on: ubuntu-latest |
| 30 | + steps: |
| 31 | + |
| 32 | + # Check out current repository |
| 33 | + - name: Fetch Sources |
| 34 | + |
| 35 | + |
| 36 | + # Validate wrapper |
| 37 | + - name: Gradle Wrapper Validation |
| 38 | + |
| 39 | + |
| 40 | + # Run verifyPlugin and test Gradle tasks |
| 41 | + test: |
| 42 | + name: Test |
| 43 | + needs: gradleValidation |
| 44 | + runs-on: ubuntu-latest |
| 45 | + steps: |
| 46 | + |
| 47 | + # Setup Java 1.8 environment for the next steps |
| 48 | + - name: Setup Java |
| 49 | + uses: actions/setup-java@v2 |
| 50 | + with: |
| 51 | + distribution: zulu |
| 52 | + java-version: 8 |
| 53 | + |
| 54 | + # Check out current repository |
| 55 | + - name: Fetch Sources |
| 56 | + |
| 57 | + |
| 58 | + # Cache Gradle dependencies |
| 59 | + - name: Setup Gradle Dependencies Cache |
| 60 | + |
| 61 | + with: |
| 62 | + path: ~/.gradle/caches |
| 63 | + key: ${{ runner.os }}-gradle-caches-${{ hashFiles('**/*.gradle', '**/*.gradle.kts', 'gradle.properties') }} |
| 64 | + |
| 65 | + # Cache Gradle Wrapper |
| 66 | + - name: Setup Gradle Wrapper Cache |
| 67 | + |
| 68 | + with: |
| 69 | + path: ~/.gradle/wrapper |
| 70 | + key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }} |
| 71 | + |
| 72 | + # Run detekt, ktlint and tests |
| 73 | + - name: Run Linters and Test |
| 74 | + run: ./gradlew check |
| 75 | + |
| 76 | + # Run verifyPlugin Gradle task |
| 77 | + - name: Verify Plugin |
| 78 | + run: ./gradlew verifyPlugin |
| 79 | + |
| 80 | + # Build plugin with buildPlugin Gradle task and provide the artifact for the next workflow jobs |
| 81 | + # Requires test job to be passed |
| 82 | + build: |
| 83 | + name: Build |
| 84 | + needs: test |
| 85 | + runs-on: ubuntu-latest |
| 86 | + outputs: |
| 87 | + name: ${{ steps.properties.outputs.name }} |
| 88 | + version: ${{ steps.properties.outputs.version }} |
| 89 | + changelog: ${{ steps.properties.outputs.changelog }} |
| 90 | + artifact: ${{ steps.properties.outputs.artifact }} |
| 91 | + steps: |
| 92 | + |
| 93 | + # Setup Java 1.8 environment for the next steps |
| 94 | + - name: Setup Java |
| 95 | + uses: actions/setup-java@v2 |
| 96 | + with: |
| 97 | + distribution: zulu |
| 98 | + java-version: 8 |
| 99 | + |
| 100 | + # Check out current repository |
| 101 | + - name: Fetch Sources |
| 102 | + |
| 103 | + |
| 104 | + # Cache Gradle Dependencies |
| 105 | + - name: Setup Gradle Dependencies Cache |
| 106 | + |
| 107 | + with: |
| 108 | + path: ~/.gradle/caches |
| 109 | + key: ${{ runner.os }}-gradle-caches-${{ hashFiles('**/*.gradle', '**/*.gradle.kts', 'gradle.properties') }} |
| 110 | + |
| 111 | + # Cache Gradle Wrapper |
| 112 | + - name: Setup Gradle Wrapper Cache |
| 113 | + |
| 114 | + with: |
| 115 | + path: ~/.gradle/wrapper |
| 116 | + key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }} |
| 117 | + |
| 118 | + # Set environment variables |
| 119 | + - name: Export Properties |
| 120 | + id: properties |
| 121 | + shell: bash |
| 122 | + run: | |
| 123 | + PROPERTIES="$(./gradlew properties --console=plain -q)" |
| 124 | + VERSION="$(echo "$PROPERTIES" | grep "^version:" | cut -f2- -d ' ')" |
| 125 | + NAME="$(echo "$PROPERTIES" | grep "^pluginName:" | cut -f2- -d ' ')" |
| 126 | + CHANGELOG="$(./gradlew getChangelog --unreleased --no-header --console=plain -q)" |
| 127 | + CHANGELOG="${CHANGELOG//'%'/'%25'}" |
| 128 | + CHANGELOG="${CHANGELOG//$'\n'/'%0A'}" |
| 129 | + CHANGELOG="${CHANGELOG//$'\r'/'%0D'}" |
| 130 | + ARTIFACT="${NAME}-${VERSION}.zip" |
| 131 | +
|
| 132 | + echo "::set-output name=version::$VERSION" |
| 133 | + echo "::set-output name=name::$NAME" |
| 134 | + echo "::set-output name=changelog::$CHANGELOG" |
| 135 | + echo "::set-output name=artifact::$ARTIFACT" |
| 136 | +
|
| 137 | + # Build artifact using buildPlugin Gradle task |
| 138 | + - name: Build Plugin |
| 139 | + run: ./gradlew buildPlugin |
| 140 | + |
| 141 | + # Upload plugin artifact to make it available in the next jobs |
| 142 | + - name: Upload artifact |
| 143 | + |
| 144 | + with: |
| 145 | + name: plugin-artifact |
| 146 | + path: ./build/distributions/${{ steps.properties.outputs.artifact }} |
| 147 | + |
| 148 | + # Verify built plugin using IntelliJ Plugin Verifier tool |
| 149 | + # Requires build job to be passed |
| 150 | + verify: |
| 151 | + name: Verify |
| 152 | + needs: build |
| 153 | + runs-on: ubuntu-latest |
| 154 | + steps: |
| 155 | + |
| 156 | + # Setup Java 1.8 environment for the next steps |
| 157 | + - name: Setup Java |
| 158 | + uses: actions/setup-java@v2 |
| 159 | + with: |
| 160 | + distribution: zulu |
| 161 | + java-version: 8 |
| 162 | + |
| 163 | + # Check out current repository |
| 164 | + - name: Fetch Sources |
| 165 | + |
| 166 | + |
| 167 | + # Cache Gradle Dependencies |
| 168 | + - name: Setup Gradle Dependencies Cache |
| 169 | + |
| 170 | + with: |
| 171 | + path: ~/.gradle/caches |
| 172 | + key: ${{ runner.os }}-gradle-caches-${{ hashFiles('**/*.gradle', '**/*.gradle.kts', 'gradle.properties') }} |
| 173 | + |
| 174 | + # Cache Gradle Wrapper |
| 175 | + - name: Setup Gradle Wrapper Cache |
| 176 | + |
| 177 | + with: |
| 178 | + path: ~/.gradle/wrapper |
| 179 | + key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }} |
| 180 | + |
| 181 | + # Set environment variables |
| 182 | + - name: Export Properties |
| 183 | + id: properties |
| 184 | + shell: bash |
| 185 | + run: | |
| 186 | + PROPERTIES="$(./gradlew properties --console=plain -q)" |
| 187 | + IDE_VERSIONS="$(echo "$PROPERTIES" | grep "^pluginVerifierIdeVersions:" | base64)" |
| 188 | +
|
| 189 | + echo "::set-output name=ideVersions::$IDE_VERSIONS" |
| 190 | + echo "::set-output name=pluginVerifierHomeDir::~/.pluginVerifier" |
| 191 | +
|
| 192 | + # Cache Plugin Verifier IDEs |
| 193 | + - name: Setup Plugin Verifier IDEs Cache |
| 194 | + |
| 195 | + with: |
| 196 | + path: ${{ steps.properties.outputs.pluginVerifierHomeDir }}/ides |
| 197 | + key: ${{ runner.os }}-plugin-verifier-${{ steps.properties.outputs.ideVersions }} |
| 198 | + |
| 199 | + # Run IntelliJ Plugin Verifier action using GitHub Action |
| 200 | + - name: Verify Plugin |
| 201 | + run: ./gradlew runPluginVerifier -Pplugin.verifier.home.dir=${{ steps.properties.outputs.pluginVerifierHomeDir }} |
| 202 | + |
| 203 | + # Prepare a draft release for GitHub Releases page for the manual verification |
| 204 | + # If accepted and published, release workflow would be triggered |
| 205 | + releaseDraft: |
| 206 | + name: Release Draft |
| 207 | + if: github.event_name != 'pull_request' |
| 208 | + needs: [build, verify] |
| 209 | + runs-on: ubuntu-latest |
| 210 | + steps: |
| 211 | + |
| 212 | + # Check out current repository |
| 213 | + - name: Fetch Sources |
| 214 | + |
| 215 | + |
| 216 | + # Remove old release drafts by using the curl request for the available releases with draft flag |
| 217 | + - name: Remove Old Release Drafts |
| 218 | + env: |
| 219 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 220 | + run: | |
| 221 | + curl -H "Authorization: Bearer $GITHUB_TOKEN" https://api.github.com/repos/$GITHUB_REPOSITORY/releases \ |
| 222 | + | tr '\r\n' ' ' \ |
| 223 | + | jq '.[] | select(.draft == true) | .id' \ |
| 224 | + | xargs -I '{}' \ |
| 225 | + curl -X DELETE -H "Authorization: Bearer $GITHUB_TOKEN" https://api.github.com/repos/$GITHUB_REPOSITORY/releases/{} |
| 226 | +
|
| 227 | + # Create new release draft - which is not publicly visible and requires manual acceptance |
| 228 | + - name: Create Release Draft |
| 229 | + id: createDraft |
| 230 | + |
| 231 | + env: |
| 232 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 233 | + with: |
| 234 | + tag_name: v${{ needs.build.outputs.version }} |
| 235 | + release_name: v${{ needs.build.outputs.version }} |
| 236 | + body: ${{ needs.build.outputs.changelog }} |
| 237 | + draft: true |
| 238 | + |
| 239 | + # Download plugin artifact provided by the previous job |
| 240 | + - name: Download Artifact |
| 241 | + uses: actions/download-artifact@v2 |
| 242 | + with: |
| 243 | + name: plugin-artifact |
| 244 | + |
| 245 | + # Upload artifact as a release asset |
| 246 | + - name: Upload Release Asset |
| 247 | + id: upload-release-asset |
| 248 | + |
| 249 | + env: |
| 250 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 251 | + with: |
| 252 | + upload_url: ${{ steps.createDraft.outputs.upload_url }} |
| 253 | + asset_path: ./${{ needs.build.outputs.artifact }} |
| 254 | + asset_name: ${{ needs.build.outputs.artifact }} |
| 255 | + asset_content_type: application/zip |
0 commit comments