Update GitHub workflows (#2464)

* Copy react project to the html branch
* Merge pipelines into fewer files & fix step names
* Rename ci.yml to CI
* Reduce job name lengths
* Automate updating version.txt
* Change sonarcloud run condition to use secret
* Fix Set up vs Setup inconsistency
This commit is contained in:
Aurora Lahtela 2022-07-06 20:45:16 +03:00 committed by GitHub
parent caa385b829
commit ea57d0dea1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 189 additions and 266 deletions

View File

@ -1,10 +1,11 @@
name: Java CI
name: CI
on: [push]
on: [push, pull_request]
jobs:
build:
test:
name: Run Tests
runs-on: ubuntu-latest
@ -24,7 +25,7 @@ jobs:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up JDK 1.16
- name: Setup JDK
uses: actions/setup-java@v2
with:
distribution: 'adopt'
@ -63,9 +64,53 @@ jobs:
cd Plan
./gradlew build
- name: SonarCloud
run: |
cd Plan
./gradlew sonar -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=player-analytics-plan
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
if: "${{ env.SONAR_TOKEN != '' }}"
run: |
cd Plan
./gradlew sonar -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=player-analytics-plan
build_dev_jars:
name: Build DEV jars
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup JDK
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '17'
- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Build with Gradle
run: |
cd Plan
./gradlew shadowJar snapshotVersion jarNameVersion
git_hash=$(git rev-parse --short "$GITHUB_SHA")
echo "git_hash=$git_hash" >> $GITHUB_ENV
echo "snapshotVersion=$(cat build/versions/snapshot.txt)" >> $GITHUB_ENV
echo "versionString=$(cat build/versions/jar.txt)" >> $GITHUB_ENV
echo "artifactPath=$(pwd)/builds" >> $GITHUB_ENV
- name: Upload Plan.jar
uses: actions/upload-artifact@v3
with:
name: Plan-${{ env.versionString }}-${{ env.git_hash }}.jar
path: ${{ env.artifactPath }}/Plan-${{ env.snapshotVersion }}.jar
- name: Upload PlanFabric.jar
uses: actions/upload-artifact@v3
with:
name: PlanFabric-${{ env.versionString }}-${{ env.git_hash }}.jar
path: ${{ env.artifactPath }}/PlanFabric-${{ env.snapshotVersion }}.jar

View File

@ -1,56 +0,0 @@
name: Upload artifact to CurseForge
on:
release:
types: [ published ]
jobs:
upload_release:
if: ${{ github.event.release.prerelease == false }}
runs-on: ubuntu-latest
steps:
- name: Download release artifact for upload
run: |
curl 'https://api.github.com/repos/plan-player-analytics/plan/releases/${{ github.event.release.id }}/assets' | jq -r '.[] | {name: .name, url: .browser_download_url} | select(.url | strings | test("Fabric"))' > asset.txt
jq -r '.url' asset.txt > url.txt
jq -r '.name' asset.txt > name.txt
wget -i url.txt
echo "JAR_FILENAME=$(cat name.txt)" >> $GITHUB_ENV
- name: Upload release to CurseForge 🚀
uses: itsmeow/curseforge-upload@master
with:
token: ${{ secrets.CF_API_TOKEN }}
project_id: 508727
game_endpoint: minecraft
file_path: ${{ env.JAR_FILENAME }}
changelog: ${{ github.event.release.body }}
changelog_type: markdown
display_name: ${{ github.event.release.name }}
game_versions: "2:Java 17,73407:1.19,Fabric"
release_type: release
relations: fabric-api:requiredDependency,luckperms:optionalDependency
upload_prerelease:
if: ${{ github.event.release.prerelease == true }}
runs-on: ubuntu-latest
steps:
- name: Download release artifact for upload
run: |
curl 'https://api.github.com/repos/plan-player-analytics/plan/releases/${{ github.event.release.id }}/assets' | jq -r '.[] | {name: .name, url: .browser_download_url} | select(.url | strings | test("Fabric"))' > asset.txt
jq -r '.url' asset.txt > url.txt
jq -r '.name' asset.txt > name.txt
wget -i url.txt
echo "JAR_FILENAME=$(cat name.txt)" >> $GITHUB_ENV
- name: Upload prerelease to CurseForge 🚀
uses: itsmeow/curseforge-upload@master
with:
token: ${{ secrets.CF_API_TOKEN }}
project_id: 508727
game_endpoint: minecraft
file_path: ${{ env.JAR_FILENAME }}
changelog: ${{ github.event.release.body }}
changelog_type: markdown
display_name: ${{ github.event.release.name }}
game_versions: "2:Java 17,73407:1.19,Fabric"
release_type: beta
relations: fabric-api:requiredDependency,luckperms:optionalDependency

View File

@ -1,46 +0,0 @@
name: Build DEV-release jars
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up JDK
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '17'
- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Build with Gradle
run: |
cd Plan
./gradlew shadowJar snapshotVersion jarNameVersion
git_hash=$(git rev-parse --short "$GITHUB_SHA")
echo "git_hash=$git_hash" >> $GITHUB_ENV
echo "snapshotVersion=$(cat build/versions/snapshot.txt)" >> $GITHUB_ENV
echo "versionString=$(cat build/versions/jar.txt)" >> $GITHUB_ENV
echo "artifactPath=$(pwd)/builds" >> $GITHUB_ENV
- name: Upload Plan.jar
uses: actions/upload-artifact@v3
with:
name: Plan-${{ env.versionString }}-${{ env.git_hash }}.jar
path: ${{ env.artifactPath }}/Plan-${{ env.snapshotVersion }}.jar
- name: Upload PlanFabric.jar
uses: actions/upload-artifact@v3
with:
name: PlanFabric-${{ env.versionString }}-${{ env.git_hash }}.jar
path: ${{ env.artifactPath }}/PlanFabric-${{ env.snapshotVersion }}.jar

View File

@ -1,68 +0,0 @@
name: Java PR CI
on: [pull_request]
jobs:
build:
runs-on: ubuntu-latest
services:
mariadb:
image: mariadb:latest
ports:
- 3306
env:
MYSQL_USER: user
MYSQL_PASSWORD: password
MYSQL_DATABASE: test
MYSQL_ROOT_PASSWORD: password
options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.16
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '17'
- name: Setup Selenium Webdriver
uses: nanasess/setup-chromedriver@v1
- name: Setup Selenium Webdriver settings
run: |
export DISPLAY=:99
chromedriver --url-base=/wd/hub &
sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 &
- name: Verify MariaDB connection
env:
PORT: ${{ job.services.mariadb.ports[3306] }}
run: |
while ! mysqladmin ping -h"127.0.0.1" -P"$PORT" --silent; do
sleep 1
done
- name: Cache Gradle packages
uses: actions/cache@v2
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Build with Gradle
env:
MYSQL_DB: test
MYSQL_USER: user
MYSQL_PASS: password
MYSQL_PORT: ${{ job.services.mariadb.ports[3306] }}
CHROMEDRIVER: /usr/local/bin/chromedriver
run: |
cd Plan
./gradlew build
- name: Cleanup Gradle cache
# Remove some files from the Gradle cache, so they aren't cached by GitHub Actions.
# Restoring these files from a GitHub Actions cache might cause problems for future builds.
run: |
rm -f ~/.gradle/caches/modules-2/modules-2.lock
rm -f ~/.gradle/caches/modules-2/gc.properties

View File

@ -1,30 +0,0 @@
# This workflow will build a Java project with Gradle
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
name: Update html-branch
on:
release:
types: [ published ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2.3.1
- name: Get git TAG
id: tagName
uses: olegtarasov/get-tag@v2.1
- name: Copy assets 🔧
run: |
mkdir -p workingdir/Plan/src/main/resources/assets/plan
cp -r Plan/common/src/main/resources/assets/plan workingdir/Plan/src/main/resources/assets/plan
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@4.0.0
with:
branch: html # The branch the action should deploy to.
folder: workingdir # The folder the action should deploy.
commit-message: ${{ steps.tagName.outputs.tag }}

View File

@ -16,7 +16,7 @@ jobs:
- name: Checkout 🛎️
uses: actions/checkout@v2.3.1
- name: Set up JDK 1.16 🍵
- name: Set up JDK 🍵
uses: actions/setup-java@v2
with:
distribution: 'adopt'

136
.github/workflows/on-release.yml vendored Normal file
View File

@ -0,0 +1,136 @@
name: Release
on:
release:
types: [ published ]
jobs:
update_versions_txt:
name: Update version.txt
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2.3.1
- name: Get Download URL
run: |
curl 'https://api.github.com/repos/plan-player-analytics/plan/releases/${{ github.event.release.id }}/assets' | jq -r '.[] | {name: .name, url: .browser_download_url} | select(.url | strings | test("Fabric") | not)' > asset.txt
jq -r '.url' asset.txt > url.txt
echo "RELEASE_DOWNLOAD_URL=$(cat url.txt)" >> $GITHUB_ENV
- name: Write REL release line
if: ${{ github.event.release.prerelease == false }}
run: |
echo "REL|${{ env.RELEASE_DOWNLOAD_URL }}|https://github.com/plan-player-analytics/Plan/releases" > release_line.txt
- name: Write DEV release line
if: ${{ github.event.release.prerelease == true }}
run: |
echo "DEV|${{ env.RELEASE_DOWNLOAD_URL }}|${{ github.event.release.url }}" > release_line.txt
- name: Append to version.txt
run: |
cat release_line.txt version.txt > version.txt
- name: Commit and push changes
uses: EndBug/add-and-commit@v9
with:
committer_name: GitHub Actions
committer_email: 41898282+github-actions[bot]@users.noreply.github.com
message: Update version.txt ${{ github.event.release.name }}
add: version.txt
update_html:
name: Update html-branch
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2.3.1
- name: Get git TAG
id: tagName
uses: olegtarasov/get-tag@v2.1
- name: Copy assets 🔧
run: |
mkdir -p workingdir/Plan/src/main/resources/assets/plan
mkdir -p workingdir/react/dashboard
cp -r Plan/common/src/main/resources/assets/plan workingdir/Plan/src/main/resources/assets/plan
cp -r react/dashboard workingdir/react/dashboard
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@4.0.0
with:
branch: html # The branch the action should deploy to.
folder: workingdir # The folder the action should deploy.
commit-message: ${{ steps.tagName.outputs.tag }}
upload_release_ore:
name: Ore Upload
runs-on: ubuntu-latest
steps:
- name: Download release artifact for upload
run: |
curl 'https://api.github.com/repos/plan-player-analytics/plan/releases/${{ github.event.release.id }}/assets' | jq -r '.[] | {name: .name, url: .browser_download_url} | select(.url | strings | test("Fabric") | not)' > asset.txt
jq -r '.url' asset.txt > url.txt
jq -r '.name' asset.txt > name.txt
wget -i url.txt
echo "JAR_FILENAME=$(cat name.txt)" >> $GITHUB_ENV
- name: Upload artifact for ore upload
uses: actions/upload-artifact@v3
with:
name: Plan.jar
path: ${{ env.JAR_FILENAME }}
- name: Upload release to Ore 🚀
if: ${{ github.event.release.prerelease == false }}
uses: dualspiral/ore-upload-action@v1
with:
plugin: ${{ github.event.release.name }}
description: ${{ github.event.release.body }}
apiKey: ${{ secrets.ORE_API_TOKEN }}
channel: Release
pluginId: plan
createForumPost: true
- name: Upload DEV release to Ore 🚀
if: ${{ github.event.release.prerelease == true }}
uses: dualspiral/ore-upload-action@v1
with:
plugin: ${{ github.event.release.name }}
description: ${{ github.event.release.body }}
apiKey: ${{ secrets.ORE_API_TOKEN }}
channel: DEV
pluginId: plan
createForumPost: false
upload_release_curseforge:
name: CurseForge Upload
runs-on: ubuntu-latest
steps:
- name: Download release artifact for upload
run: |
curl 'https://api.github.com/repos/plan-player-analytics/plan/releases/${{ github.event.release.id }}/assets' | jq -r '.[] | {name: .name, url: .browser_download_url} | select(.url | strings | test("Fabric"))' > asset.txt
jq -r '.url' asset.txt > url.txt
jq -r '.name' asset.txt > name.txt
wget -i url.txt
echo "JAR_FILENAME=$(cat name.txt)" >> $GITHUB_ENV
- name: Upload release to CurseForge 🚀
if: ${{ github.event.release.prerelease == false }}
uses: itsmeow/curseforge-upload@master
with:
token: ${{ secrets.CF_API_TOKEN }}
project_id: 508727
game_endpoint: minecraft
file_path: ${{ env.JAR_FILENAME }}
changelog: ${{ github.event.release.body }}
changelog_type: markdown
display_name: ${{ github.event.release.name }}
game_versions: "2:Java 17,73407:1.19,Fabric"
release_type: release
relations: fabric-api:requiredDependency,luckperms:optionalDependency
- name: Upload prerelease to CurseForge 🚀
if: ${{ github.event.release.prerelease == true }}
uses: itsmeow/curseforge-upload@master
with:
token: ${{ secrets.CF_API_TOKEN }}
project_id: 508727
game_endpoint: minecraft
file_path: ${{ env.JAR_FILENAME }}
changelog: ${{ github.event.release.body }}
changelog_type: markdown
display_name: ${{ github.event.release.name }}
game_versions: "2:Java 17,73407:1.19,Fabric"
release_type: beta
relations: fabric-api:requiredDependency,luckperms:optionalDependency

View File

@ -1,58 +0,0 @@
name: Upload artifact to Ore
on:
release:
types: [ published ]
jobs:
upload_release:
if: ${{ github.event.release.prerelease == false }}
runs-on: ubuntu-latest
steps:
- name: Download release artifact for upload
run: |
curl 'https://api.github.com/repos/plan-player-analytics/plan/releases/${{ github.event.release.id }}/assets' | jq -r '.[] | {name: .name, url: .browser_download_url} | select(.url | strings | test("Fabric") | not)' > asset.txt
jq -r '.url' asset.txt > url.txt
jq -r '.name' asset.txt > name.txt
wget -i url.txt
echo "JAR_FILENAME=$(cat name.txt)" >> $GITHUB_ENV
- name: Upload artifact for ore upload
uses: actions/upload-artifact@v3
with:
name: Plan.jar
path: ${{ env.JAR_FILENAME }}
- name: Upload release to Ore 🚀
uses: dualspiral/ore-upload-action@v1
with:
plugin: ${{ github.event.release.name }}
description: ${{ github.event.release.body }}
apiKey: ${{ secrets.ORE_API_TOKEN }}
channel: Release
pluginId: plan
createForumPost: true
upload_prerelease:
if: ${{ github.event.release.prerelease == true }}
runs-on: ubuntu-latest
steps:
- name: Download release artifact for upload
run: |
curl 'https://api.github.com/repos/plan-player-analytics/plan/releases/${{ github.event.release.id }}/assets' | jq -r '.[] | {name: .name, url: .browser_download_url} | select(.url | strings | test("Fabric") | not)' > asset.txt
jq -r '.url' asset.txt > url.txt
jq -r '.name' asset.txt > name.txt
wget -i url.txt
echo "JAR_FILENAME=$(cat name.txt)" >> $GITHUB_ENV
- name: Upload artifact for ore upload
uses: actions/upload-artifact@v3
with:
name: Plan.jar
path: ${{ env.JAR_FILENAME }}
- name: Upload release to Ore 🚀
uses: dualspiral/ore-upload-action@v1
with:
plugin: ${{ github.event.release.name }}
description: ${{ github.event.release.body }}
apiKey: ${{ secrets.ORE_API_TOKEN }}
channel: DEV
pluginId: plan
createForumPost: false