Skip to content

Commit

Permalink
Backport test system and other changes to 1.21.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander01998 committed Dec 17, 2024
1 parent 0d2564c commit 62a31e9
Show file tree
Hide file tree
Showing 16 changed files with 1,267 additions and 121 deletions.
17 changes: 17 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: "gradle"
directory: "/"
schedule:
interval: "daily"

- package-ecosystem: "github-actions"
# Directory should be `/` instead of `/.github/workflows` according to the docs.
directory: "/"
schedule:
interval: "daily"
113 changes: 113 additions & 0 deletions .github/workflows/auto_snapshot_update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Experimental workflow to automate updating to a new Minecraft snapshot.
name: Auto Snapshot Update

on:
workflow_dispatch:
inputs:
mc_version:
description: "Minecraft version to update to"
required: true
yarn_mappings:
description: "Yarn mappings version"
required: true
fabric_loader:
description: "Fabric Loader version"
required: true
fapi_version:
description: "Fabric API version"
required: true
cf_game_version:
description: "CurseForge GameVersion"
required: true

permissions:
# To push changes to the new snapshot branch.
contents: write
# To trigger the CI workflow.
actions: write

jobs:
update:
runs-on: ubuntu-latest
steps:

- name: Checkout repository
uses: actions/checkout@v4
with:
# Include all branches in case the new snapshot branch already exists.
fetch-depth: 0

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Set up Java 21
uses: actions/setup-java@v4
with:
java-version: "21"
distribution: "microsoft"

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
with:
build-scan-publish: true
build-scan-terms-of-use-url: "https://gradle.com/help/legal-terms-of-use"
build-scan-terms-of-use-agree: "yes"

- name: Create and checkout new snapshot branch
run: |
BRANCH_NAME="${{ github.event.inputs.mc_version }}"
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "$CURRENT_BRANCH" = "$BRANCH_NAME" ]; then
echo "Already on branch $BRANCH_NAME. Skipping branch creation."
elif git show-ref --quiet refs/heads/$BRANCH_NAME; then
echo "Branch $BRANCH_NAME already exists but is not currently checked out. Failing the workflow."
exit 1
else
git checkout -b $BRANCH_NAME
echo "Created and checked out new branch: $BRANCH_NAME"
fi
shell: bash

- name: Run migrateMappings task
run: |
./gradlew migrateMappings --mappings ${{ github.event.inputs.yarn_mappings }}
shell: bash

- name: Replace src/main/java with remapped files
run: |
rm -rf ./src/main/java
mv ./remappedSrc ./src/main/java
shell: bash

- name: Update version constants
run: |
python scripts/update_version_constants.py "${{ github.event.inputs.mc_version }}" "${{ github.event.inputs.yarn_mappings }}" "${{ github.event.inputs.fabric_loader }}" "${{ github.event.inputs.fapi_version }}" "${{ github.event.inputs.cf_game_version }}"
shell: bash

# To fix any style issues that the migration scripts might cause
- name: Run spotlessApply task
run: ./gradlew spotlessApply

- name: Commit and push changes
run: |
git config --global user.name "Wurst-Bot"
git config --global user.email "[email protected]"
git add .
git commit -m "[Wurst-Bot] Update to ${{ github.event.inputs.mc_version }}"
git push --set-upstream origin ${{ github.event.inputs.mc_version }}
shell: bash

# For some reason the commit above doesn't automatically trigger the CI
# workflow, so we need to explicitly start it here.
- name: Trigger CI on the new branch
env:
GH_TOKEN: ${{ github.token }}
run: |
gh workflow run gradle.yml --ref ${{ github.event.inputs.mc_version }}
shell: bash
40 changes: 40 additions & 0 deletions .github/workflows/dependency_graph.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Update Gradle Dependency Graph

on:
push:
branches:
# Submitting dependency graph reports on non-default branches does nothing
- "master"
tags-ignore:
- "**"
paths:
- "gradle**"
- "*.gradle"
workflow_dispatch:

permissions:
contents: write

jobs:
dependency-submission:
runs-on: ubuntu-latest
steps:

- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Java 21
uses: actions/setup-java@v4
with:
java-version: "21"
distribution: "microsoft"

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Generate and submit dependency graph
uses: gradle/actions/dependency-submission@v4
with:
build-scan-publish: true
build-scan-terms-of-use-url: "https://gradle.com/help/legal-terms-of-use"
build-scan-terms-of-use-agree: "yes"
130 changes: 108 additions & 22 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,41 @@ name: Java CI with Gradle

on:
push:
branches-ignore:
- "dependabot/**"
tags-ignore:
- "**"
paths:
- '**.java'
- '**.json'
- 'gradle**'
- 'build.gradle'
- "**.java"
- "**.json"
- "**.yml"
- "gradle**"
- "*.gradle"
pull_request:
paths:
- '**.java'
- '**.json'
- 'gradle**'
- 'build.gradle'
# Makes it possible to run this workflow manually from the Actions tab
- "**.java"
- "**.json"
- "**.yml"
- "gradle**"
- "*.gradle"
workflow_dispatch:

permissions:
contents: write

jobs:
build:
runs-on: ubuntu-latest

env:
VIRUSTOTAL_API_KEY: ${{ secrets.VIRUSTOTAL_API_KEY }}
IMGUR_CLIENT_ID: ${{ secrets.IMGUR_CLIENT_ID }}
steps:

- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Java 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'microsoft'
java-version: "21"
distribution: "microsoft"

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand All @@ -42,19 +47,100 @@ jobs:
build-scan-publish: true
build-scan-terms-of-use-url: "https://gradle.com/help/legal-terms-of-use"
build-scan-terms-of-use-agree: "yes"
# Enable cache writing for NeoForge branches, since they don't benefit from the Fabric cache on master
cache-read-only: ${{ github.ref != 'refs/heads/master' && !contains(github.ref, 'neoforge') }}

- name: Compile Java code
run: ./gradlew remapJar --stacktrace --warning-mode=fail

- name: Validate JSON files
run: ./gradlew spotlessJsonCheck || (echo "::error::JSON validation failed! Run './gradlew spotlessApply' to fix style issues, or check the full error message for syntax errors." && exit 1)

- name: Generate and submit dependency graph
if: ${{ github.event_name == 'push' }}
uses: gradle/actions/dependency-submission@v4
- name: Validate Java code style
run: ./gradlew spotlessJavaCheck || (echo "::error::Java code style validation failed! To fix, run 'Clean Up' and then 'Format' in Eclipse, or './gradlew spotlessApply' in the terminal." && exit 1)

- name: Run tests and build
- name: Run unit tests
run: ./gradlew test --stacktrace --warning-mode=fail

- name: Validate access widener
run: ./gradlew validateAccessWidener --stacktrace --warning-mode=fail

- name: Build
run: ./gradlew build --stacktrace --warning-mode=fail

- name: VirusTotal scan
if: ${{ github.event_name == 'push' }}
- name: Upload to VirusTotal for analysis
id: virustotal
if: ${{ env.VIRUSTOTAL_API_KEY }}
uses: crazy-max/ghaction-virustotal@v4
with:
vt_api_key: ${{ secrets.VIRUSTOTAL_API_KEY }}
vt_api_key: ${{ env.VIRUSTOTAL_API_KEY }}
files: |
./build/libs/*.jar
# An error in this step means that the upload failed, not that a false
# positive was detected.
continue-on-error: true

- name: Add VirusTotal links to build summary
if: ${{ env.VIRUSTOTAL_API_KEY && steps.virustotal.outputs.analysis }}
shell: bash
run: |
echo "<details open>" >> $GITHUB_STEP_SUMMARY
echo "<summary>🛡️ VirusTotal Scans</summary>" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
IFS=',' read -ra ANALYSIS <<< "${{ steps.virustotal.outputs.analysis }}"
for i in "${ANALYSIS[@]}"; do
filepath=${i%%=*}
url=${i#*=}
filename=$(basename "$filepath")
echo "- [$filename]($url)" >> $GITHUB_STEP_SUMMARY
done
echo "</details>" >> $GITHUB_STEP_SUMMARY
- name: Run the mod and take screenshots
uses: modmuss50/xvfb-action@c56c7da0c8fc9a7cb5df2e50dd2a43a80b64c5cb
with:
run: ./gradlew runEndToEndTest --stacktrace --warning-mode=fail

# Needed because the screenshot gallery won't be created on pull requests.
# Also useful if Imgur uploads fail.
- name: Upload Test Screenshots.zip artifact
uses: actions/upload-artifact@v4
if: always()
with:
name: Test Screenshots
path: run/screenshots

- name: Create test screenshot gallery
if: ${{ env.IMGUR_CLIENT_ID && (success() || failure()) }}
shell: bash
run: |
echo "<details open>" >> $GITHUB_STEP_SUMMARY
echo "<summary>📸 Test Screenshots</summary>" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
for img in run/screenshots/*.png; do
if [ -f "$img" ]; then
filename=$(basename "$img")
name_without_ext="${filename%.*}"
# Upload to Imgur
response=$(curl -s -X POST \
-H "Authorization: Client-ID $IMGUR_CLIENT_ID" \
-F "image=@$img" \
https://api.imgur.com/3/image)
# Extract the URL from the response
url=$(echo $response | grep -o '"link":"[^"]*"' | cut -d'"' -f4)
if [ ! -z "$url" ]; then
# Convert underscores to spaces and capitalize first letter of each word
title=$(echo "$name_without_ext" | tr '_' ' ' | awk '{for(i=1;i<=NF;i++)sub(/./,toupper(substr($i,1,1)),$i)}1')
echo "### $title" >> $GITHUB_STEP_SUMMARY
echo "![${name_without_ext}]($url)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
else
echo "Failed to upload $filename" >> $GITHUB_STEP_SUMMARY
fi
fi
done
echo "</details>" >> $GITHUB_STEP_SUMMARY
20 changes: 0 additions & 20 deletions .github/workflows/jsonsyntax.yml

This file was deleted.

Loading

0 comments on commit 62a31e9

Please sign in to comment.