Gradle Plugin Release #9
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Gradle Plugin Release | |
on: | |
release: | |
types: [created] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
packages: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@v4 | |
- name: Build Plugin with Gradle | |
run: ./gradlew buildPlugin | |
- name: Get Previous Tag | |
id: previous_tag | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const { data: tags } = await github.rest.repos.listTags({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
per_page: 2, | |
}); | |
if (tags.length < 2) { | |
core.setFailed("Not enough tags to generate release notes."); | |
} else { | |
core.setOutput("previous_tag", tags[1].name); | |
} | |
- name: Generate Release Notes | |
id: generate_notes | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const previousTag = "${{ steps.previous_tag.outputs.previous_tag }}"; | |
const currentTag = "${{ github.event.release.tag_name }}"; | |
const { data: commits } = await github.rest.repos.compareCommits({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
base: previousTag, | |
head: currentTag, | |
}); | |
let releaseNotes = '### Changelog\n\n'; | |
commits.commits.forEach(commit => { | |
releaseNotes += `- ${commit.commit.message}\n`; | |
}); | |
core.setOutput("notes", releaseNotes); | |
- name: Update Release with Notes | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const { data: release } = await github.rest.repos.getReleaseByTag({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
tag: context.payload.release.tag_name, | |
}); | |
await github.rest.repos.updateRelease({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
release_id: release.id, | |
body: `${{ steps.generate_notes.outputs.notes }}`, | |
}); | |
- name: Upload Plugin to GitHub Release | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ github.event.release.upload_url }} | |
asset_path: ./build/libs/SecurityInspector-${{ github.event.release.tag_name }}.jar | |
asset_name: SecurityInspector-${{ github.event.release.tag_name }}.jar | |
asset_content_type: application/java-archive |