workflow-release #6
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: Sync Schema on Workflow Release | |
| on: | |
| repository_dispatch: | |
| types: [workflow-release] | |
| permissions: | |
| contents: write | |
| jobs: | |
| sync: | |
| name: Update schema and release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.REPO_DISPATCH_TOKEN }} | |
| - name: Setup Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.26' | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@v3 | |
| with: | |
| gradle-home-cache-cleanup: true | |
| - name: Install wfctl | |
| env: | |
| GOPRIVATE: github.com/GoCodeAlone/* | |
| GONOSUMCHECK: github.com/GoCodeAlone/* | |
| GOFLAGS: -buildvcs=false | |
| run: | | |
| WORKFLOW_VERSION="${{ github.event.client_payload.version }}" | |
| go install "github.com/GoCodeAlone/workflow/cmd/wfctl@${WORKFLOW_VERSION}" | |
| - name: Regenerate schema | |
| run: wfctl schema --output src/main/resources/schemas/workflow-config.schema.json | |
| - name: Render templates | |
| run: | | |
| export WORKFLOW_VERSION="${{ github.event.client_payload.version }}" | |
| envsubst '${WORKFLOW_VERSION}' < README.md.tmpl > README.md | |
| envsubst '${WORKFLOW_VERSION}' < src/main/resources/META-INF/plugin.xml.tmpl > src/main/resources/META-INF/plugin.xml | |
| - name: Compute plugin version | |
| id: version | |
| run: | | |
| WORKFLOW_VERSION="${{ github.event.client_payload.version }}" | |
| VERSION="${WORKFLOW_VERSION#v}" | |
| MAJOR=$(echo "$VERSION" | cut -d. -f1) | |
| MINOR=$(echo "$VERSION" | cut -d. -f2) | |
| PATCH=$(echo "$VERSION" | cut -d. -f3) | |
| BASE=$((PATCH * 100)) | |
| CURRENT_VERSION=$(grep '^pluginVersion=' gradle.properties | cut -d= -f2) | |
| CURRENT_PATCH=$(echo "$CURRENT_VERSION" | cut -d. -f3) | |
| if [ "$CURRENT_PATCH" -ge "$BASE" ] && [ "$CURRENT_PATCH" -lt "$((BASE + 100))" ]; then | |
| PLUGIN_PATCH=$((CURRENT_PATCH + 1)) | |
| else | |
| PLUGIN_PATCH=$BASE | |
| fi | |
| PLUGIN_VERSION="${MAJOR}.${MINOR}.${PLUGIN_PATCH}" | |
| echo "PLUGIN_VERSION=${PLUGIN_VERSION}" >> "$GITHUB_OUTPUT" | |
| echo "Engine ${WORKFLOW_VERSION} → plugin v${PLUGIN_VERSION}" | |
| - name: Bump plugin version | |
| run: | | |
| PLUGIN_VERSION="${{ steps.version.outputs.PLUGIN_VERSION }}" | |
| sed -i "s/^pluginVersion=.*/pluginVersion=${PLUGIN_VERSION}/" gradle.properties | |
| - name: Build plugin | |
| run: ./gradlew buildPlugin | |
| - name: Run tests | |
| run: ./gradlew test | |
| - name: Commit and tag | |
| run: | | |
| WORKFLOW_VERSION="${{ github.event.client_payload.version }}" | |
| PLUGIN_VERSION="v${{ steps.version.outputs.PLUGIN_VERSION }}" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add -A | |
| git diff --cached --quiet && echo "No changes" && exit 0 | |
| git commit -m "chore: sync schema and version to workflow ${WORKFLOW_VERSION} (plugin ${PLUGIN_VERSION})" | |
| git push | |
| if git rev-parse "${PLUGIN_VERSION}" >/dev/null 2>&1; then | |
| echo "Tag ${PLUGIN_VERSION} already exists, skipping" | |
| else | |
| git tag "${PLUGIN_VERSION}" | |
| git push origin "${PLUGIN_VERSION}" | |
| fi |