Merge pull request #179 from hackclub/java-gradle-update #229
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: HCCore | |
on: | |
push: | |
branches: | |
- '*' | |
tags: | |
- v*.*.* | |
- v*.*.*-rc.* | |
pull_request: | |
jobs: | |
validation: | |
name: "Validate Gradle Wrapper" | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: gradle/wrapper-validation-action@v1 | |
build: | |
if: (!startsWith(github.ref, 'refs/tags/v')) | |
needs: validation | |
runs-on: ubuntu-latest | |
name: Gradle Build | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Setup Java | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'temurin' | |
java-version: 17 | |
java-package: jdk | |
- uses: actions/cache@v3 | |
id: gradle-cache | |
with: | |
path: ~/.gradle/caches | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/gradle/dependency-locks/*.lockfile') }} | |
restore-keys: | | |
- ${{ runner.os }}-gradle- | |
- uses: actions/cache@v3 | |
id: gradle-wrapper-cache | |
with: | |
path: ~/.gradle/wrapper | |
key: ${{ runner.os }}-gradlewrapper-${{ hashFiles('gradle/wrapper/*') }} | |
restore-keys: | | |
- ${{ runner.os }}-gradlewrapper- | |
- name: Gradle build | |
run: ./gradlew --build-cache --info --stacktrace build -Prelease.state=dev | |
- name: Upload jar to build artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: built-plugin | |
path: build/libs/HCCore-Shadow-*.jar | |
release: | |
if: startsWith(github.ref, 'refs/tags/v') | |
needs: validation | |
runs-on: ubuntu-latest | |
name: Gradle Build Release | |
outputs: | |
release-assets: steps..outputs.assets | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Setup Java | |
uses: actions/setup-java@v3 | |
with: | |
distribution: 'temurin' | |
java-version: 17 | |
java-package: jdk | |
- uses: actions/cache@v3 | |
id: gradle-cache | |
with: | |
path: ~/.gradle/caches | |
key: ${{ runner.os }}-gradle-${{ hashFiles('**/gradle/dependency-locks/*.lockfile') }} | |
restore-keys: | | |
- ${{ runner.os }}-gradle- | |
- uses: actions/cache@v3 | |
id: gradle-wrapper-cache | |
with: | |
path: ~/.gradle/wrapper | |
key: ${{ runner.os }}-gradlewrapper-${{ hashFiles('gradle/wrapper/*') }} | |
restore-keys: | | |
- ${{ runner.os }}-gradlewrapper- | |
- name: Publish candidate | |
if: | | |
startsWith(github.ref, 'refs/tags/v') && | |
contains(github.ref, '-rc.') | |
run: ./gradlew --build-cache --info --stacktrace -Prelease.useLastTag=true candidate | |
- name: Publish release | |
if: | | |
startsWith(github.ref, 'refs/tags/v') && | |
(!contains(github.ref, '-rc.')) | |
run: ./gradlew --build-cache --info --stacktrace -Prelease.useLastTag=true final | |
- name: Upload jar to build artifacts | |
uses: actions/upload-artifact@v3 | |
with: | |
name: built-plugin | |
path: build/libs/HCCore-Shadow-*.jar | |
- name: Release | |
id: add-gh-release | |
uses: softprops/action-gh-release@v1 | |
with: | |
generate_release_notes: ${{ !(contains(github.ref, '-rc.')) }} # full releases only | |
prerelease: ${{ contains(github.ref, '-rc.') }} | |
files: "build/libs/HCCore-Shadow-*.jar" | |
deploy: | |
if: | | |
startsWith(github.ref, 'refs/tags/v') && | |
(!contains(github.ref, '-rc.')) | |
needs: release | |
runs-on: ubuntu-latest | |
name: Deploy to Production Server | |
steps: | |
- name: Download released version | |
uses: actions/download-artifact@v3 | |
with: | |
name: built-plugin | |
- name: SCP Deploy | |
env: | |
SSH_PRIVATE_KEY: ${{ secrets.MINECRAFT_DEPLOY_SSH_KEY }} | |
run: | | |
echo "$SSH_PRIVATE_KEY" > .ssh_private_key | |
chmod 700 .ssh_private_key | |
mkdir -p ~/.ssh/ && touch ~/.ssh/known_hosts | |
ssh-keyscan mc-admin.hackclub.com >> ~/.ssh/known_hosts | |
eval $(ssh-agent) | |
ssh-add - <<< "$SSH_PRIVATE_KEY" | |
scp -i .ssh_private_key HCCore-Shadow-*.jar github-deploy@mc-admin.hackclub.com:/opt/minecraft/plugins/update | |
rm .ssh_private_key | |