update #22
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: Java CI with Gradle | |
on: | |
push: | |
branches: [ "master" ] | |
pull_request: | |
branches: [ "master" ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'temurin' | |
- name: Set executable permissions for gradlew | |
run: chmod +x ./gradlew | |
- name: Build with Gradle Wrapper | |
run: ./gradlew clean build | |
env: | |
GITHUB_ACTOR: ${{secrets.MY_GITHUB_ACTOR}} | |
GITHUB_TOKEN: ${{secrets.MY_GITHUB_TOKEN}} | |
- name: Upload JAR artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: example-ayaka-artifact | |
path: build/libs/example-ayaka-*.*.*-SNAPSHOT.jar | |
upload: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Configure SSH key before upload the file | |
run: | | |
mkdir -p ~/.ssh | |
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
echo "Host *" >> ~/.ssh/config | |
echo " StrictHostKeyChecking no" >> ~/.ssh/config | |
echo "${{ secrets.SSH_HOST }} ${HOST_KEY}" >> ~/.ssh/known_hosts | |
- name: Download JAR artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: example-ayaka-artifact | |
path: artifact | |
- name: SCP Files | |
run: | | |
scp -P ${{ secrets.SSH_PORT }} \ | |
artifact/* \ | |
${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }}:${{ secrets.SSH_WORK_PATH }} | |
- name: Restart project | |
run: | | |
ssh -p ${{ secrets.SSH_PORT }} \ | |
${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_HOST }} "cd ${{ secrets.SSH_WORK_PATH }} \ | |
&& cd .. && ./restart.sh" | |
- name: Cleanup SSH key | |
if: always() | |
run: | | |
rm -f ~/.ssh/id_rsa | |
rm -f ~/.ssh/config | |
rm -f ~/.ssh/known_hosts | |