Skip to content

Build and Deploy Snapshots to a GitHub Branch #12

Build and Deploy Snapshots to a GitHub Branch

Build and Deploy Snapshots to a GitHub Branch #12

Workflow file for this run

name: Build
on:
push:
branches: [ develop, next ]
# pull_request:
# branches: [ '**' ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up the Java JDK
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'adopt'
- name: Build and Deploy Snapshots to a GitHub Branch
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: |
# Set up a local repository branch for Maven deployment
SNAPSHOT_BRANCH="maven-snapshots"
git config --global user.name "github-actions"
git config --global user.email "github-actions@github.com"
# Clone the target branch for deployment
git clone --branch "$SNAPSHOT_BRANCH" "https://${GH_ACTOR}:${GH_TOKEN}@github.com/${{ github.repository }}.git" target-branch || \
git clone --branch main "https://${GH_ACTOR}:${GH_TOKEN}@github.com/${{ github.repository }}.git" target-branch
# Build the project and deploy to the local repo branch
mvn clean deploy -DaltDeploymentRepository=snapshot-repo::default::file://$(pwd)/target-branch/repo
# Push the updated snapshots to the branch
cd target-branch
git add repo
git commit -m "Deploy new snapshots [skip ci]" || echo "No changes to commit"
git push origin "$SNAPSHOT_BRANCH"
- name: Generate JaCoCo Badge
id: jacoco
uses: cicirello/jacoco-badge-generator@v2
with:
badges-directory: badges
generate-branches-badge: true
generate-summary: true
- name: Log coverage percentage
run: |
echo "coverage = ${{ steps.jacoco.outputs.coverage }}"
echo "branch coverage = ${{ steps.jacoco.outputs.branches }}"
- name: Comment on PR with coverage percentages
if: ${{ github.event_name == 'pull_request' }}
run: |
REPORT=$(<badges/zenwave-sdk-cli/coverage-summary.json)
COVERAGE=$(jq -r '.coverage' <<< "$REPORT")%
BRANCHES=$(jq -r '.branches' <<< "$REPORT")%
NEWLINE=$'\n'
BODY="## JaCoCo Test Coverage Summary Statistics (zenwave-sdk-cli)${NEWLINE}* __Coverage:__ ${COVERAGE}${NEWLINE}* __Branches:__ ${BRANCHES}"
gh pr comment ${{github.event.pull_request.number}} -b "${BODY}"
continue-on-error: true
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}