|
| 1 | +name: Snapshot Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +jobs: |
| 9 | + build-and-release: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - name: Checkout code |
| 14 | + uses: actions/checkout@v4 |
| 15 | + |
| 16 | + - name: Set up JDK 8 |
| 17 | + uses: actions/setup-java@v4 |
| 18 | + with: |
| 19 | + java-version: '8' |
| 20 | + distribution: 'temurin' |
| 21 | + |
| 22 | + - name: Build with Maven |
| 23 | + run: mvn clean package -DskipTests |
| 24 | + |
| 25 | + - name: Get commit info |
| 26 | + id: commit |
| 27 | + run: | |
| 28 | + echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT |
| 29 | + echo "build_time=$(date)" >> $GITHUB_OUTPUT |
| 30 | +
|
| 31 | + - name: Delete previous pre-releases |
| 32 | + uses: actions/github-script@v7 |
| 33 | + with: |
| 34 | + script: | |
| 35 | + const { owner, repo } = context.repo; |
| 36 | + const releases = await github.rest.repos.listReleases({ owner, repo }); |
| 37 | + for (const rel of releases.data) { |
| 38 | + if (rel.prerelease && rel.tag_name.startsWith("snapshot-")) { |
| 39 | + console.log(`Deleting old pre-release: ${rel.tag_name}`); |
| 40 | + try { |
| 41 | + await github.rest.repos.deleteRelease({ owner, repo, release_id: rel.id }); |
| 42 | + } catch (e) { |
| 43 | + console.warn(`Failed to delete release ${rel.tag_name}:`, e.message); |
| 44 | + } |
| 45 | + try { |
| 46 | + await github.rest.git.deleteRef({ owner, repo, ref: `tags/${rel.tag_name}` }); |
| 47 | + } catch (e) { |
| 48 | + console.warn(`Failed to delete tag ${rel.tag_name}:`, e.message); |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | +
|
| 53 | + - name: Rename artifact |
| 54 | + run: | |
| 55 | + mkdir -p dist |
| 56 | + SRC_JAR=$(ls target/*.jar | head -n 1) |
| 57 | + NEW_JAR="dist/JNDIMap-snapshot-${{ steps.commit.outputs.sha_short }}.jar" |
| 58 | + cp "$SRC_JAR" "$NEW_JAR" |
| 59 | + echo "Renamed artifact to $NEW_JAR" |
| 60 | +
|
| 61 | + - name: Create Pre-release |
| 62 | + uses: softprops/action-gh-release@v2 |
| 63 | + with: |
| 64 | + tag_name: snapshot-${{ steps.commit.outputs.sha_short }} |
| 65 | + name: snapshot-${{ steps.commit.outputs.sha_short }} |
| 66 | + body: | |
| 67 | + Release created at ${{ steps.commit.outputs.build_time }}. |
| 68 | + Latest snapshot build of **JNDIMap** on *main* branch. |
| 69 | + prerelease: true |
| 70 | + make_latest: true |
| 71 | + files: | |
| 72 | + dist/*.jar |
| 73 | + env: |
| 74 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments