|
| 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 project |
| 16 | + concurrency: |
| 17 | + group: stage-build-${{ github.ref }} |
| 18 | + cancel-in-progress: true |
| 19 | + steps: |
| 20 | + - name: Checkout sources |
| 21 | + uses: actions/checkout@v6 |
| 22 | + |
| 23 | + - name: Set up Java 21 |
| 24 | + uses: actions/setup-java@v5 |
| 25 | + with: |
| 26 | + distribution: temurin |
| 27 | + java-version: 21 |
| 28 | + cache: maven |
| 29 | + |
| 30 | + - name: Build with Maven |
| 31 | + env: |
| 32 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 33 | + run: mvn package -B -DskipTests -Dskip.junit_platform=true |
| 34 | + |
| 35 | + - name: Upload JAR artifacts |
| 36 | + uses: actions/upload-artifact@v7 |
| 37 | + with: |
| 38 | + name: distributions |
| 39 | + path: | |
| 40 | + ./target/trustify-da-java-client-*.jar |
| 41 | + !./target/original-*.jar |
| 42 | +
|
| 43 | + release: |
| 44 | + runs-on: ubuntu-latest |
| 45 | + name: Create an early-access release |
| 46 | + concurrency: |
| 47 | + group: stage-release-${{ github.ref }} |
| 48 | + cancel-in-progress: false |
| 49 | + permissions: |
| 50 | + contents: write |
| 51 | + needs: build |
| 52 | + if: github.repository_owner == 'guacsec' |
| 53 | + steps: |
| 54 | + - name: Checkout sources |
| 55 | + uses: actions/checkout@v6 |
| 56 | + |
| 57 | + - name: Download distribution artifacts |
| 58 | + uses: actions/download-artifact@v4 |
| 59 | + with: |
| 60 | + name: distributions |
| 61 | + path: ./distributions |
| 62 | + |
| 63 | + - name: Check for existing early-access release |
| 64 | + id: existing_release |
| 65 | + uses: actions/github-script@v7 |
| 66 | + with: |
| 67 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 68 | + script: | |
| 69 | + const repo_name = context.payload.repository.full_name |
| 70 | + try { |
| 71 | + const response = await github.request('GET /repos/' + repo_name + '/releases/tags/early-access') |
| 72 | + core.setOutput('id', response.data.id) |
| 73 | + } catch (error) { |
| 74 | + if (error.status === 404) { |
| 75 | + core.info('No existing early-access release found') |
| 76 | + core.setOutput('id', '') |
| 77 | + } else { |
| 78 | + core.setFailed(`Failed to check for early-access release: ${error.status} ${error.message}`) |
| 79 | + } |
| 80 | + } |
| 81 | +
|
| 82 | + - name: Delete early-access release if exists |
| 83 | + if: ${{ steps.existing_release.outputs.id }} |
| 84 | + uses: actions/github-script@v7 |
| 85 | + with: |
| 86 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 87 | + script: | |
| 88 | + const repo_name = context.payload.repository.full_name |
| 89 | + await github.request('DELETE /repos/' + repo_name + '/releases/' + ${{ steps.existing_release.outputs.id }}) |
| 90 | +
|
| 91 | + - name: Delete early-access tag if exists |
| 92 | + continue-on-error: true |
| 93 | + run: git push --delete origin early-access |
| 94 | + |
| 95 | + # a little pause between deleting the release and creating a new one |
| 96 | + # without it, the new release might be a weird release, i.e. a draft release |
| 97 | + - name: Sleep 5 |
| 98 | + run: sleep 5 |
| 99 | + |
| 100 | + - name: Create new early-access release |
| 101 | + id: new_release |
| 102 | + uses: actions/github-script@v7 |
| 103 | + with: |
| 104 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 105 | + script: | |
| 106 | + const repo_name = context.payload.repository.full_name |
| 107 | + const response = await github.request('POST /repos/' + repo_name + '/releases', { |
| 108 | + tag_name: 'early-access', |
| 109 | + name: 'Early-Access', |
| 110 | + draft: false, |
| 111 | + prerelease: true, |
| 112 | + generate_release_notes: true, |
| 113 | + make_latest: 'false' |
| 114 | + }) |
| 115 | + core.setOutput('upload_url', response.data.upload_url) |
| 116 | +
|
| 117 | + - name: Create SHA256 checksums for the binaries |
| 118 | + working-directory: distributions |
| 119 | + run: | |
| 120 | + short_sha="${{ github.sha }}" |
| 121 | + short_sha="${short_sha:0:7}" |
| 122 | + # Rename JAR files to include short commit ID and create checksums |
| 123 | + for pkg in *.jar; do |
| 124 | + [ ! -f "$pkg" ] && continue |
| 125 | + new_filename="${pkg%.jar}-${short_sha}.jar" |
| 126 | + echo "Renaming $pkg to $new_filename" |
| 127 | + mv "$pkg" "$new_filename" |
| 128 | + echo "Creating checksum for $new_filename" |
| 129 | + sha256sum "$new_filename" > "$new_filename.sha256" |
| 130 | + done |
| 131 | +
|
| 132 | + - name: Upload packages and checksums as early-access release assets |
| 133 | + working-directory: distributions |
| 134 | + run: | |
| 135 | + set -euo pipefail |
| 136 | + for file in * |
| 137 | + do |
| 138 | + asset_name=$(basename "$file") |
| 139 | + upload_url=$(echo "${{ steps.new_release.outputs.upload_url }}" | sed "s/{?name,label}/?name=$asset_name/g") |
| 140 | + echo "Uploading $asset_name..." |
| 141 | + curl --fail-with-body --retry 3 --retry-all-errors --show-error --silent \ |
| 142 | + --data-binary @"$file" \ |
| 143 | + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ |
| 144 | + -H "Content-Type: application/octet-stream" \ |
| 145 | + "$upload_url" |
| 146 | + echo "" |
| 147 | + done |
0 commit comments