Skip to content

HanhNg23 is practicing GitHub Actions to run code java file from the src code in HanhNg23/Java-Lab-Projects #1

HanhNg23 is practicing GitHub Actions to run code java file from the src code in HanhNg23/Java-Lab-Projects

HanhNg23 is practicing GitHub Actions to run code java file from the src code in HanhNg23/Java-Lab-Projects #1

Workflow file for this run

name: run-java-file
run-name: ${{ github.actor }} is practicing GitHub Actions to run code java file from the src code in ${{ github.repository }}
on:
workflow_dispatch:
inputs:
java-main-file-directory:
description: "Provide the directory of the Java file containing the main method in the src workspace"
required: true
default: 'directory of class contain main method'
type: string
jobs:
# job1
check-condition: # job id
strategy:
matrix:
# os: [ubuntu-latest, macOS-latest, windows-latest]
os: [windows-latest]
runs-on: ${{ matrix.os }} # type of machine to run the job on
if: ${{ github.event_name == 'workflow_dispatch' && github.ref_type == 'branch'}}
outputs:
result-check: ${{ steps.check-correct-format.outputs.result }}
steps:
- name: Check input directory
id: check-correct-format
if: ${{ endsWith(inputs.java-main-file-directory, '.java') }}
run: echo "result=true" >> $GITHUB_OUTPUT
# job2
running-java-file: # job id
needs: check-condition
strategy:
matrix:
os: [windows-latest]
runs-on: ${{ matrix.os }} # type of machine to run the job on
if: ${{ needs.check-condition.outputs.result-check }} == 'true' && github.event_name == 'workflow_dispatch' && github.ref_type == 'branch' }}
steps:
- uses: actions/checkout@v4
- name: Setup Java JDK
uses: actions/[email protected]
with:
java-version: '17'
distribution: 'oracle'
java-package: jdk # The package type (jdk, jre, jdk+fx, jre+fx) defaults to jdk
- name: Display JDK version
run: java --version
- name: Run Java file
run: java ${{ inputs.java-main-file-directory }}
- run: echo "📢 Completed workflow "