|
| 1 | +--- |
| 2 | +name: Stage |
| 3 | + |
| 4 | +on: |
| 5 | + workflow_dispatch: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + paths-ignore: |
| 10 | + - ".github/**" |
| 11 | + |
| 12 | +jobs: |
| 13 | + build: |
| 14 | + runs-on: ubuntu-latest |
| 15 | + name: Build plugin |
| 16 | + steps: |
| 17 | + - name: Checkout sources |
| 18 | + uses: actions/checkout@v3 |
| 19 | + |
| 20 | + - name: Install Java 17 |
| 21 | + uses: actions/setup-java@v3 |
| 22 | + with: |
| 23 | + java-version: 17 |
| 24 | + distribution: 'oracle' |
| 25 | + |
| 26 | + - name: Build plugin with Gradle |
| 27 | + uses: gradle/gradle-build-action@v2 |
| 28 | + with: |
| 29 | + arguments: buildPlugin |
| 30 | + |
| 31 | + - name: Upload distribution archive as artifact |
| 32 | + uses: actions/upload-artifact@v3 |
| 33 | + with: |
| 34 | + name: distributions |
| 35 | + path: ./build/distributions |
| 36 | + |
| 37 | + release: |
| 38 | + runs-on: ubuntu-latest |
| 39 | + name: Create an early-access release |
| 40 | + environment: staging |
| 41 | + needs: build |
| 42 | + if: github.repository == 'redhat-developer/intellij-dependency-analytics' |
| 43 | + steps: |
| 44 | + - name: Download distribution artifacts |
| 45 | + uses: actions/download-artifact@v3 |
| 46 | + with: |
| 47 | + name: distributions |
| 48 | + path: ./distributions |
| 49 | + |
| 50 | + - name: Check for existing early-access release |
| 51 | + id: existing_release |
| 52 | + uses: actions/github-script@v6 |
| 53 | + continue-on-error: true |
| 54 | + with: |
| 55 | + github-token: ${{ secrets.STAGING_PAT }} |
| 56 | + script: | |
| 57 | + const repo_name = context.payload.repository.full_name |
| 58 | + var response = await github.request('GET /repos/' + repo_name + '/releases/tags/early-access') |
| 59 | + // if the request fails (ie 404) the next steps will not occur and the output will not be set |
| 60 | + core.setOutput('id', response.data.id) |
| 61 | +
|
| 62 | + - name: Delete early-access release if exists |
| 63 | + if: ${{ steps.existing_release.outputs.id }} |
| 64 | + uses: actions/github-script@v6 |
| 65 | + with: |
| 66 | + github-token: ${{ secrets.STAGING_PAT }} |
| 67 | + script: | |
| 68 | + const repo_name = context.payload.repository.full_name |
| 69 | + await github.request('DELETE /repos/' + repo_name + '/releases/' + ${{ steps.existing_release.outputs.id }}) |
| 70 | +
|
| 71 | + - name: Delete early-access tag if exists |
| 72 | + continue-on-error: true |
| 73 | + run: git push --delete origin early-access |
| 74 | + |
| 75 | + # a little pause between deleting the release and creating a new one |
| 76 | + # without it, the new release might be a weird release, i.e. a draft release |
| 77 | + - name: Sleep 5 |
| 78 | + run: sleep 5 |
| 79 | + |
| 80 | + - name: Create new early-access release |
| 81 | + id: new_release |
| 82 | + uses: actions/github-script@v6 |
| 83 | + with: |
| 84 | + github-token: ${{ secrets.STAGING_PAT }} |
| 85 | + script: | |
| 86 | + const repo_name = context.payload.repository.full_name |
| 87 | + const response = await github.request('POST /repos/' + repo_name + '/releases', { |
| 88 | + tag_name: 'early-access', |
| 89 | + name: 'Early-Access', |
| 90 | + draft: false, |
| 91 | + prerelease: true, |
| 92 | + generate_release_notes: true, |
| 93 | + make_latest: 'false' |
| 94 | + }) |
| 95 | + core.setOutput('upload_url', response.data.upload_url) |
| 96 | +
|
| 97 | + - name: Create SHA256 checksums for the binaries |
| 98 | + working-directory: distributions |
| 99 | + run: | |
| 100 | + for pkg in * |
| 101 | + do |
| 102 | + sha256sum "$pkg" > "$pkg.sha256" |
| 103 | + done |
| 104 | +
|
| 105 | + - name: Upload packages and checksums as early-access release assets |
| 106 | + working-directory: distributions |
| 107 | + run: | |
| 108 | + for file in * |
| 109 | + do |
| 110 | + asset_name=$(basename "$file") |
| 111 | + upload_url=$(echo "${{ steps.new_release.outputs.upload_url }}" | sed "s/{?name,label}/?name=$asset_name/g") |
| 112 | + curl --data-binary @"$file" \ |
| 113 | + -H "Authorization: token ${{ secrets.STAGING_PAT }}" \ |
| 114 | + -H "Content-Type: application/octet-stream" \ |
| 115 | + "$upload_url" |
| 116 | + done |
0 commit comments