WIP fixes from rebase #3465
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: Build | |
on: [ push, pull_request ] | |
jobs: | |
prepare: | |
name: Prepare Build Variables | |
runs-on: ubuntu-latest | |
outputs: | |
VERSION: ${{ steps.version.outputs.VERSION }} | |
VERSION_TYPE: ${{ steps.version.outputs.VERSION_TYPE }} | |
VERSION_MAVEN: ${{ steps.version.outputs.VERSION_MAVEN }} | |
VERSION_IS_NEW: ${{ steps.version.outputs.VERSION_IS_NEW }} | |
steps: | |
- name: Checkout source code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- uses: BetonQuest/Workflows/.github/actions/version@main | |
id: version | |
with: | |
ROOT_REPOSITORY: BetonQuest/BetonQuest | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
EXCLUDE_PATHS: | | |
docs | |
build-code: | |
name: Build Code | |
needs: [ prepare ] | |
runs-on: ubuntu-latest | |
env: | |
VERSION: ${{ needs.prepare.outputs.VERSION }} | |
VERSION_TYPE: ${{ needs.prepare.outputs.VERSION_TYPE }} | |
VERSION_MAVEN: ${{ needs.prepare.outputs.VERSION_MAVEN }} | |
VERSION_IS_NEW: ${{ needs.prepare.outputs.VERSION_IS_NEW }} | |
steps: | |
- name: Checkout source code | |
uses: actions/checkout@v4 | |
- uses: BetonQuest/Workflows/.github/actions/setup-java-maven@main | |
with: | |
JAVA_CACHE: 'maven' | |
MAVEN_TARGET_DIR: 'target/artifacts' | |
- uses: BetonQuest/Workflows/.github/actions/replace-code-variables@main | |
with: | |
VERSION: ${{ env.VERSION }} | |
VERSION_TYPE: ${{ env.VERSION_TYPE }} | |
VERSION_NAMESPACE: "betonquest" | |
- name: Build with Maven. Phase 'verify' | |
shell: bash --noprofile --norc -euo pipefail {0} | |
run: | | |
if [ $VERSION_TYPE == 'release' ]; then CHANGELIST=-Dchangelist=; fi | |
./mvnw ${CHANGELIST-} -P Test-All -B verify | |
git diff > target/artifacts/changes.patch | |
- name: Upload Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: BetonQuest-Artifacts | |
path: | | |
target/artifacts/BetonQuest.jar | |
target/artifacts/betonquest-*-*.jar | |
build-docs: | |
name: Build Docs | |
needs: [ prepare ] | |
runs-on: ubuntu-latest | |
env: | |
VERSION: ${{ needs.prepare.outputs.VERSION }} | |
VERSION_TYPE: ${{ needs.prepare.outputs.VERSION_TYPE }} | |
VERSION_MAVEN: ${{ needs.prepare.outputs.VERSION_MAVEN }} | |
VERSION_IS_NEW: ${{ needs.prepare.outputs.VERSION_IS_NEW }} | |
steps: | |
- name: Checkout source code | |
uses: actions/checkout@v4 | |
with: | |
submodules: ${{ env.VERSION_TYPE == 'release' || env.VERSION_TYPE == 'development' }} | |
- uses: BetonQuest/Workflows/.github/actions/setup-git-lfs@main | |
- uses: BetonQuest/Workflows/.github/actions/setup-mkdocs-material@main | |
with: | |
MKDOCS_MATERIAL_INSIDERS: ${{ secrets.MKDOCS_MATERIAL_INSIDERS }} | |
MKDOCS_SITE_DIR: 'target/docs' | |
PYTHON_CACHE: 'pip' | |
PYTHON_CACHE_DEPENDENCY_PATH: 'docs/setup-docs-dependencies.py' | |
- uses: ./.github/actions/replace-docs-variables | |
with: | |
VERSION: ${{ env.VERSION }} | |
VERSION_TYPE: ${{ env.VERSION_TYPE }} | |
VERSION_MAVEN: ${{ env.VERSION_MAVEN }} | |
REPOSITORY_URL: ${{ vars.REPOSITORY_URL }} | |
- name: Build with mkdocs | |
shell: bash --noprofile --norc -euo pipefail {0} | |
run: | | |
mkdocs build --strict | |
git diff > target/docs/changes.patch | |
env: | |
MKDOCS_MATERIAL_INSIDERS_ENABLED: ${{ secrets.MKDOCS_MATERIAL_INSIDERS != '' }} | |
MKDOCS_MATERIAL_INSIDERS_ENABLED_CI: ${{ secrets.MKDOCS_MATERIAL_INSIDERS != '' }} | |
- name: Upload Docs | |
uses: actions/upload-artifact@v4 | |
with: | |
name: BetonQuest-Docs | |
path: | | |
target/docs/ | |
!target/docs/changes.patch | |
deploy-code: | |
name: Deploy Code | |
if: "needs.prepare.outputs.VERSION_TYPE == 'release' || needs.prepare.outputs.VERSION_TYPE == 'development' && needs.prepare.outputs.VERSION_IS_NEW == 'true'" | |
needs: [ prepare, build-code, build-docs ] | |
runs-on: ubuntu-latest | |
env: | |
VERSION: ${{ needs.prepare.outputs.VERSION }} | |
VERSION_TYPE: ${{ needs.prepare.outputs.VERSION_TYPE }} | |
VERSION_MAVEN: ${{ needs.prepare.outputs.VERSION_MAVEN }} | |
VERSION_IS_NEW: ${{ needs.prepare.outputs.VERSION_IS_NEW }} | |
outputs: | |
UPLOAD_PATH: ${{ steps.save_upload_path.outputs.upload_path }} | |
steps: | |
- name: Checkout source code | |
uses: actions/checkout@v4 | |
- uses: BetonQuest/Workflows/.github/actions/setup-java-maven@main | |
with: | |
JAVA_CACHE: 'maven' | |
JAVA_REPOSITORY_ID: 'betonquest' | |
JAVA_REPOSITORY_USER: MAVEN_SERVER_USERNAME | |
JAVA_REPOSITORY_PASS: MAVEN_SERVER_PASSWORD | |
MAVEN_TARGET_DIR: 'target/artifacts' | |
- name: Load patch file | |
shell: bash --noprofile --norc -euo pipefail {0} | |
run: | | |
git apply target/artifacts/changes.patch | |
rm target/artifacts/changes.patch | |
- name: Publish to Maven Repository | |
shell: bash --noprofile --norc -euo pipefail {0} | |
run: | | |
if [ $VERSION_TYPE == 'release' ]; then CHANGELIST=-Dchangelist=; fi | |
./mvnw ${CHANGELIST-} -P Skip-Verification,Test-None -B deploy | tee maven-deploy.log | |
env: | |
REPOSITORY_URL: ${{ vars.REPOSITORY_URL }} | |
MAVEN_SERVER_USERNAME: ${{ secrets.MAVEN_SERVER_USERNAME }} | |
MAVEN_SERVER_PASSWORD: ${{ secrets.MAVEN_SERVER_PASSWORD }} | |
- name: Get upload URL from deploy log | |
id: save_upload_path | |
shell: bash --noprofile --norc -euo pipefail {0} | |
run: | | |
UPLOAD_PATH="$(grep -oP "(?<=Uploading to betonquest: $REPOSITORY_URL).*-shaded.jar" maven-deploy.log)" | |
echo "upload_path=$UPLOAD_PATH" >> $GITHUB_OUTPUT | |
env: | |
REPOSITORY_URL: ${{ vars.REPOSITORY_URL }} | |
deploy-docs: | |
name: Deploy Docs | |
concurrency: gh-pages-deploy | |
if: "needs.prepare.outputs.VERSION_TYPE == 'release' || needs.prepare.outputs.VERSION_TYPE == 'development'" | |
needs: [ prepare, build-code, build-docs ] | |
runs-on: ubuntu-latest | |
env: | |
VERSION: ${{ needs.prepare.outputs.VERSION }} | |
VERSION_TYPE: ${{ needs.prepare.outputs.VERSION_TYPE }} | |
VERSION_MAVEN: ${{ needs.prepare.outputs.VERSION_MAVEN }} | |
VERSION_IS_NEW: ${{ needs.prepare.outputs.VERSION_IS_NEW }} | |
steps: | |
- name: Checkout source code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
submodules: ${{ env.VERSION_TYPE == 'release' }} | |
token: ${{ secrets.ALL_REPOSITORIES_ACCESS_TOKEN }} | |
- uses: BetonQuest/Workflows/.github/actions/setup-git-lfs@main | |
- uses: BetonQuest/Workflows/.github/actions/setup-mkdocs-material@main | |
with: | |
MKDOCS_MATERIAL_INSIDERS: ${{ secrets.MKDOCS_MATERIAL_INSIDERS }} | |
MKDOCS_SITE_DIR: 'target/docs' | |
PYTHON_CACHE: 'pip' | |
PYTHON_CACHE_DEPENDENCY_PATH: 'docs/setup-docs-dependencies.py' | |
- name: Load patch file | |
shell: bash --noprofile --norc -euo pipefail {0} | |
run: | | |
git apply target/docs/changes.patch | |
rm target/docs/changes.patch | |
- name: Deploy to Github Pages | |
if: "env.VERSION_TYPE == 'release' || env.VERSION_TYPE == 'development'" | |
shell: bash --noprofile --norc -euo pipefail {0} | |
run: | | |
git config --global user.name "BetonQuest-Bot" | |
git config --global user.email "[email protected]" | |
IFS='.' read -r major minor _ <<< "$VERSION" | |
TWO_DIGIT_VERSION="$major.$minor" | |
FLAGS=(--push --update-aliases) | |
VERSIONS=() | |
if [ "$VERSION_TYPE" = release ]; then | |
VERSIONS+=("$TWO_DIGIT_VERSION" "$TWO_DIGIT_VERSION-DEV") | |
if [ -n "$(git branch -r --contains tags/v${VERSION} --remote origin/main)" ]; then | |
VERSIONS+=(RELEASE DEV) | |
elif { mike list --json "$TWO_DIGIT_VERSION" | grep -q '"aliases" *: *\[[^]]*"RELEASE"'; }; then | |
VERSIONS+=(RELEASE) | |
fi | |
echo "mike delete $TWO_DIGIT_VERSION-DEV" | |
mike delete "$TWO_DIGIT_VERSION-DEV" | |
elif [ "$VERSION_TYPE" = development ]; then | |
VERSIONS+=("$TWO_DIGIT_VERSION-DEV") | |
if ! { mike list --json | grep -q "\"version\" *: *\"$TWO_DIGIT_VERSION\""; }; then | |
VERSIONS+=("$TWO_DIGIT_VERSION") | |
fi | |
if [ ${{ github.ref }} == 'refs/heads/main' ]; then | |
VERSIONS+=(DEV); | |
OLD_DEV_VERSION=$(mike list --json DEV | awk -F\" '/version/{print $4}') | |
if [ "$TWO_DIGIT_VERSION-DEV" != "$OLD_DEV_VERSION" ] && [[ "$OLD_DEV_VERSION" == *"-DEV" ]]; then | |
echo "mike delete $OLD_DEV_VERSION" | |
mike delete "$OLD_DEV_VERSION" | |
echo "mike alias ${OLD_DEV_VERSION%-DEV} $OLD_DEV_VERSION" | |
mike alias ${OLD_DEV_VERSION%-DEV} $OLD_DEV_VERSION | |
fi | |
fi | |
fi | |
echo "mike deploy ${FLAGS[@]} ${VERSIONS[@]}" | |
mike deploy "${FLAGS[@]}" "${VERSIONS[@]}" | |
env: | |
MKDOCS_MATERIAL_INSIDERS_ENABLED: ${{ secrets.MKDOCS_MATERIAL_INSIDERS != '' }} | |
MKDOCS_MATERIAL_INSIDERS_ENABLED_CI: ${{ secrets.MKDOCS_MATERIAL_INSIDERS != '' }} | |
- name: Set version Tag for Quest-Tutorials submodule | |
if: "env.VERSION_TYPE == 'release'" | |
shell: bash --noprofile --norc -euo pipefail {0} | |
run: | | |
git config --global user.name "BetonQuest-Bot" | |
git config --global user.email "[email protected]" | |
cd docs/_tutorials/ | |
git tag "v$VERSION" | |
git push origin "v$VERSION" | |
create-release: | |
name: Create GitHub Release | |
if: "needs.prepare.outputs.VERSION_TYPE == 'release' && needs.deploy-code.result == 'success' && needs.deploy-docs.result == 'success'" | |
needs: [ prepare, deploy-code, deploy-docs ] | |
runs-on: ubuntu-latest | |
env: | |
VERSION: ${{ needs.prepare.outputs.VERSION }} | |
VERSION_TYPE: ${{ needs.prepare.outputs.VERSION_TYPE }} | |
VERSION_MAVEN: ${{ needs.prepare.outputs.VERSION_MAVEN }} | |
VERSION_IS_NEW: ${{ needs.prepare.outputs.VERSION_IS_NEW }} | |
steps: | |
- name: Checkout source code | |
uses: actions/checkout@v4 | |
- uses: BetonQuest/Workflows/.github/actions/setup-java-maven/cache@main | |
with: | |
MAVEN_TARGET_DIR: 'target/artifacts' | |
- uses: BetonQuest/Workflows/.github/actions/setup-mkdocs-material/cache@main | |
with: | |
MKDOCS_SITE_DIR: 'target/docs' | |
- name: Zip Docs | |
shell: bash --noprofile --norc -euo pipefail {0} | |
run: | | |
zip -r target/docs/Docs.zip target/docs/ | |
- name: Set CHANGELOG.md version | |
shell: bash --noprofile --norc -euo pipefail {0} | |
run: | | |
sed -i "s~## \[Unreleased\]~## \[${VERSION}\]~g" ./CHANGELOG.md | |
DATE="$(date +%Y-%m-%d)" | |
sed -i "s~\${maven\.build\.timestamp}~$DATE~g" ./CHANGELOG.md | |
- name: Create release | |
uses: docker://antonyurchenko/git-release:v6 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
DRAFT_RELEASE: false | |
PRE_RELEASE: false | |
CHANGELOG_FILE: CHANGELOG.md | |
RELEASE_NAME: BetonQuest ${{ env.VERSION }} | |
with: | |
args: | | |
target/artifacts/BetonQuest.jar | |
target/docs/Docs.zip | |
discord-announcement: | |
name: Official Deployment | |
if: "always() && !cancelled() && ( needs.prepare.outputs.VERSION_TYPE == 'release' || needs.prepare.outputs.VERSION_TYPE == 'development' && ( needs.prepare.outputs.VERSION_IS_NEW == 'true' || failure() ) )" | |
needs: [ prepare, deploy-code, deploy-docs, create-release ] | |
runs-on: ubuntu-latest | |
env: | |
VERSION: ${{ needs.prepare.outputs.VERSION }} | |
VERSION_TYPE: ${{ needs.prepare.outputs.VERSION_TYPE }} | |
VERSION_MAVEN: ${{ needs.prepare.outputs.VERSION_MAVEN }} | |
VERSION_IS_NEW: ${{ needs.prepare.outputs.VERSION_IS_NEW }} | |
steps: | |
- name: Checkout source code | |
uses: actions/checkout@v4 | |
- name: Set NEEDED_JOB_STATES | |
if: always() && !cancelled() | |
shell: bash --noprofile --norc -euo pipefail {0} | |
run: | | |
if [[ "${{ needs.prepare.result }}" == "failure" || "${{ needs.deploy-code.result }}" == "failure" || "${{ needs.deploy-docs.result }}" == "failure" || "${{ needs.create-release.result }}" == "failure" ]]; then | |
echo "NEEDED_JOB_STATES=failure" >> $GITHUB_ENV | |
else | |
echo "NEEDED_JOB_STATES=success" >> $GITHUB_ENV | |
fi | |
- name: Publish to Discord | |
if: "always() && !cancelled()" | |
shell: bash --noprofile --norc -euo pipefail {0} | |
run: | | |
bash .github/scripts/discord.sh | |
env: | |
JOB_STATUS: ${{ env.NEEDED_JOB_STATES }} | |
WEBHOOK_URL: ${{ secrets.WEBHOOK_URL }} | |
DOCS_URL: ${{ vars.DOCS_URL }} | |
UPLOAD_PATH: ${{ needs.deploy-code.outputs.UPLOAD_PATH }} |