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: CI for Java Project | |
on: | |
pull_request: | |
branches: | |
- main | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v2 | |
with: | |
distribution: 'temurin' | |
java-version: '17' | |
- name: Install dependencies and run tests | |
run: mvn install -B | |
- name: Run tests | |
run: mvn test --no-transfer-progress | |
javadoc: | |
runs-on: ubuntu-latest | |
needs: test # Ensures the javadoc phase runs only after the test phase succeeds | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v2 | |
with: | |
distribution: 'temurin' | |
java-version: '17' | |
- name: Generate Javadoc | |
run: mvn javadoc:javadoc --no-transfer-progress | |
- name: Verify Javadoc | |
run: | | |
if [ ! -d target/site/apidocs ]; then | |
echo "Javadoc failed to compile!" | |
exit 1 | |
fi | |
update-docs: | |
runs-on: ubuntu-latest | |
needs: [test, javadoc] # This ensures that deploy phase runs only after both test and javadoc phases succeed | |
if: github.event.pull_request.merged == true # Ensures this runs only when the PR is merged | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up SSH for deploy key | |
run: | | |
mkdir -p ~/.ssh | |
echo "${{ secrets.DEPLOY_KEY }}" > ~/.ssh/deploy_key | |
chmod 600 ~/.ssh/deploy_key | |
ssh-keyscan github.com >> ~/.ssh/known_hosts | |
env: | |
SSH_AUTH_SOCK: /tmp/ssh_agent.sock | |
- name: Generate Javadoc | |
run: mvn javadoc:javadoc --no-transfer-progress | |
- name: Deploy docs to GitHub Pages | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "github-actions[bot]@users.noreply.github.com" | |
git remote set-url origin [email protected]:${{ github.repository }}.git | |
rm -rf docs/apidocs | |
mv target/site/apidocs docs/apidocs | |
git add docs/apidocs | |
git commit -m "Update Javadoc" | |
git push origin gh-pages | |
env: | |
GIT_SSH_COMMAND: "ssh -i ~/.ssh/deploy_key -o IdentitiesOnly=yes" |