Publish Release #73
This file contains hidden or 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: Publish | |
| run-name: ${{ inputs.release && 'Publish Release' || 'Publish Snapshot' }} | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| release: | |
| default: false | |
| required: false | |
| type: boolean | |
| description: Create a Release | |
| permissions: | |
| contents: write | |
| statuses: write | |
| env: | |
| ORG_GRADLE_PROJECT_neoform_release: ${{ inputs.release }} | |
| jobs: | |
| publish: | |
| name: ${{ inputs.release && 'Publish Release' || 'Publish Snapshot' }} | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.get-version.outputs.version }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup Java | |
| uses: neoforged/actions/setup-java@main | |
| with: | |
| java-version: 21 | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v4 | |
| - name: Compute Project Version | |
| id: get-version | |
| run: ./gradlew :getVersion | |
| - uses: neoforged/action-webhooks@v1 | |
| name: Send Discord start notification | |
| with: | |
| webhook_url: ${{ secrets.DISCORD_WEBHOOK }} | |
| status: 'started' | |
| version: ${{ steps.get-version.outputs.version }} | |
| include_commit_message: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - uses: neoforged/action-github-status@v1 | |
| name: Set pending status | |
| with: | |
| authToken: ${{ secrets.GITHUB_TOKEN }} | |
| context: 'Publishing' | |
| state: 'pending' | |
| description: "Version: ${{ steps.get-version.outputs.version }}" | |
| target_url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
| - name: Tests | |
| run: ./gradlew check | |
| - name: Tag Release | |
| if: ${{ inputs.release }} | |
| run: | | |
| # Create and push tag. | |
| echo "Creating and pushing tag $TAG_NAME" | |
| # See https://github.com/actions/checkout?tab=readme-ov-file#push-a-commit-using-the-built-in-token | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git tag -a "$TAG_NAME" -m "Release $VERSION" | |
| # Try to push the tag (will fail if it exists remotely) | |
| if ! git push origin "$TAG_NAME" 2>&1; then | |
| echo "Tag already exists on remote, verifying..." | |
| TAG_COMMIT=$(git ls-remote origin "refs/tags/$TAG_NAME^{}" | awk '{print $1}') | |
| HEAD_COMMIT=$(git rev-parse HEAD) | |
| if [ "$TAG_COMMIT" != "$HEAD_COMMIT" ]; then | |
| echo "Error: Tag $TAG_NAME points to $TAG_COMMIT, not HEAD $HEAD_COMMIT" | |
| exit 1 | |
| fi | |
| echo "Tag $TAG_NAME exists, but correctly points to current HEAD" | |
| fi | |
| env: | |
| VERSION: ${{ steps.get-version.outputs.version }} | |
| TAG_NAME: v${{ steps.get-version.outputs.version }} | |
| - name: Publish | |
| run: ./gradlew publish | |
| env: | |
| MAVEN_USER: ${{ secrets.MAVEN_USER }} | |
| MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} | |
| notify-build-end: | |
| name: Build notifications (end) | |
| needs: [ "publish" ] | |
| if: ${{ always() }} | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: neoforged/action-webhooks@v1 | |
| name: Send Discord end notification | |
| with: | |
| webhook_url: ${{ secrets.DISCORD_WEBHOOK }} | |
| status: ${{ needs.publish.result }} | |
| version: ${{ needs.publish.outputs.version }} | |
| include_commit_message: true | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - uses: neoforged/action-github-status@v1 | |
| name: Set build status | |
| with: | |
| authToken: ${{ secrets.GITHUB_TOKEN }} | |
| context: 'Publishing' | |
| state: ${{ needs.publish.result }} | |
| description: "Version: ${{ needs.publish.outputs.version }}" | |
| target_url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |