Skip to content

Deploy

Deploy #271

Workflow file for this run

name: Deploy
on:
workflow_dispatch:
inputs:
dry-run:
description: "Run the steps without deploying anything"
default: false
type: boolean
skip-maven-release:
description: "Skip the Maven release and rollback steps"
default: false
type: boolean
skip-pages:
description: "Skip the creation and release of the documentation"
default: false
type: boolean
skip-tests:
description: "Skip unit and integration tests on Maven steps"
default: false
type: boolean
version:
description: "Override the deployment version (leave empty to compute the appropriate value)"
default: ""
type: string
jobs:
prepare:
name: Prepare
runs-on: ubuntu-latest
outputs:
release_version: ${{ steps.determine_version_to_release.outputs.release_version }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 2
- name: Initialize Java
uses: actions/setup-java@v5
with:
distribution: zulu
java-version: 25
- name: Compute release version
id: determine_version_to_release
run: |-
if [[ '${{ inputs.version }}' == "" ]]; then
release_version="$(./mvnw -B help:evaluate -Dexpression=project.version -q -DforceStdout | sed 's/-SNAPSHOT//g')"
else
release_version='${{ inputs.version }}'
fi
echo "release_version=${release_version}" >> "${GITHUB_OUTPUT}"
maven-central-release:
name: Maven Central Release
runs-on: ubuntu-latest
needs:
- prepare
permissions:
contents: write
id-token: write
if: ${{ ! inputs.skip-maven-release }}
environment:
name: Maven Central
url: https://repo1.maven.org/maven2/io/github/ascopes/protobuf-maven-plugin/
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 2
- name: Initialize Java
uses: actions/setup-java@v5
with:
distribution: zulu
java-version: 25
server-id: central
server-username: CENTRAL_USERNAME
server-password: CENTRAL_TOKEN
gpg-passphrase: GPG_PASSPHRASE
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
- name: Install dependencies
run: |-
scripts/prepare-runner.sh
scripts/install-protoc-to-github-runner.sh
scripts/install-grpc-java-to-github-runner.sh
- name: Configure Git
run: |-
git config user.name '${{ github.actor }}'
git config user.email '${{ github.actor }}@users.noreply.github.com'
- name: Create Maven Central release
run: |-
./mvnw -B -e \
-DdryRun='${{ inputs.dry-run }}' \
-Dinvoker.skip='${{ inputs.skip-tests }}' \
-Dpassword='${{ secrets.GITHUB_TOKEN }}' \
-DreleaseVersion="${{ needs.prepare.outputs.release_version }}" \
-DsignTag=false \
-Dmaven.test.skip='${{ inputs.skip-tests }}' \
-Dtag="v${{ needs.prepare.outputs.release_version }}" \
clean verify release:prepare release:perform
env:
CENTRAL_USERNAME: ${{ secrets.CENTRAL_USERNAME }}
CENTRAL_TOKEN: ${{ secrets.CENTRAL_TOKEN }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
- name: Upload build logs as artifacts
uses: actions/upload-artifact@v7
if: always()
with:
name: logs
path: |-
**/build.log
**/maven-status/**
**/surefire-reports/**.txt
**/surefire-reports/**.xml
compression-level: 9
retention-days: 90 # max
include-hidden-files: true
if-no-files-found: warn
- name: Revert Maven Central release
if: ${{ failure() && ! inputs.dry-run }}
run: |-
./mvnw -B -e \
-Dpassword='${{ secrets.GITHUB_TOKEN }}' \
-DreleaseVersion="${{ needs.prepare.outputs.release_version }}" \
-Dtag="v${{ needs.prepare.outputs.release_version }}" \
release:rollback
- name: Create GitHub release
if: ${{ ! failure() && ! inputs.dry-run }}
uses: ncipollo/release-action@v1
with:
tag: v${{ needs.prepare.outputs.release_version }}
name: v${{ needs.prepare.outputs.release_version }}
generateReleaseNotes: false
token: ${{ secrets.GITHUB_TOKEN }}
github-pages:
name: GitHub Pages Release
runs-on: ubuntu-latest
needs:
- prepare
permissions:
id-token: write
pages: write
if: ${{ ! inputs.skip-pages }}
environment:
name: GitHub Pages
url: https://${{ github.actor }}.github.io/protobuf-maven-plugin
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
fetch-depth: 2
- name: Initialize Java
uses: actions/setup-java@v5
with:
distribution: zulu
java-version: 25
- name: Generate site
run: |-
./mvnw -B versions:set -DnewVersion="${{ needs.prepare.outputs.release_version }}"
./mvnw -B site -Dlicense.skip -Dcheckstyle.skip -Dmaven.test.skip -Dinvoker.skip
- name: Upload site to GitHub API
if: ${{ ! inputs.dry-run }}
uses: actions/upload-pages-artifact@v4
with:
path: protobuf-maven-plugin/target/site
- name: Deploy site to GitHub Pages
if: ${{ ! inputs.dry-run }}
uses: actions/deploy-pages@v5
# If the deployment failed due to an internal error (e.g. an outage on GitHub),
# then we may get stuck in a state where we are unable to rerun this step. This
# happens because we create duplicate artifact uploads and the upload artifact
# action mishandles duplicates. The easiest way around this is to just purge the
# artifact if we failed so that any rerun can succeed.
- name: Remove GitHub Pages artifacts
uses: geekyeggo/delete-artifact@v6
if: ${{ failure() && ! inputs.dry-run }}
with:
name: github-pages
failOnError: false