Generate data #2755
This file contains hidden or 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: "Generate data" | |
| env: | |
| GENERATED_BRANCH: 'generated' | |
| PROCESSED_BRANCH: 'processed' | |
| BADGE_BRANCH: 'badge' | |
| DATA_PATH: './generated_data' | |
| DATA_NAME: 'data' | |
| REPORTS_PATH: './generated_reports' | |
| REPORTS_NAME: 'reports' | |
| on: | |
| schedule: | |
| - cron: '30 * * * *' # Runs at 30 minutes past the hour, every day | |
| workflow_call: | |
| inputs: | |
| version: | |
| description: "Generate data for a specific version. Leave blank for latest version." | |
| type: string | |
| required: false | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "Generate data for a specific version. Leave blank for latest version." | |
| type: string | |
| required: false | |
| permissions: | |
| contents: write | |
| actions: read | |
| jobs: | |
| version: | |
| name: "Version (\"${{ inputs.version || github.event.client_payload.version || 'fetch latest' }}\")" | |
| runs-on: ubuntu-24.04 | |
| env: | |
| INPUT_VERSION: ${{ inputs.version || github.event.client_payload.version }} | |
| steps: | |
| - name: 'Get Manifest information' | |
| id: 'manifest' | |
| uses: MinecraftPlayground/manifest@main | |
| with: | |
| version: ${{ env.INPUT_VERSION || 'latest-snapshot' }} | |
| if-version-is-invalid: 'error' | |
| - name: 'Checkout repository' | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: 'Check for existing version tag' | |
| id: 'check-for-existing-tag' | |
| run: | | |
| version="${{ env.INPUT_VERSION || steps.manifest.outputs.latest-snapshot-version }}" | |
| tag="${version// /_}" | |
| if git show-ref --tags --verify --quiet "refs/tags/$tag"; then | |
| echo "Tag \"$tag\" already exists. Skipping next jobs." | |
| echo "TAG_EXISTS=TRUE" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "Tag \"$tag\" does not exist. Running next jobs." | |
| echo "TAG_EXISTS=FALSE" >> "$GITHUB_OUTPUT" | |
| fi | |
| outputs: | |
| TAG_EXISTS: ${{ steps.check-for-existing-tag.outputs.TAG_EXISTS }} | |
| INPUT_VERSION: ${{ inputs.version || github.event.client_payload.version }} | |
| SELECTED_VERSION: ${{ inputs.version || github.event.client_payload.version || steps.manifest.outputs.latest-snapshot-version }} | |
| LATEST_RELEASE: ${{ steps.manifest.outputs.latest-release-version }} | |
| LATEST_SNAPSHOT: ${{ steps.manifest.outputs.latest-snapshot-version }} | |
| generate-new-data: | |
| name: "Generate new data" | |
| runs-on: ubuntu-24.04 | |
| needs: [version] | |
| if: needs.version.outputs.TAG_EXISTS == 'FALSE' | |
| env: | |
| SELECTED_VERSION: ${{ needs.version.outputs.SELECTED_VERSION }} | |
| LATEST_SNAPSHOT: ${{ needs.version.outputs.LATEST_SNAPSHOT }} | |
| steps: | |
| - name: 'Generate data for version "${{ env.SELECTED_VERSION }}" to "${{ env.DATA_PATH }}"' | |
| id: 'generate_data' | |
| uses: MinecraftPlayground/generate-data@main | |
| with: | |
| version: ${{ env.SELECTED_VERSION }} | |
| path: ${{ env.DATA_PATH }} | |
| - name: 'Upload generated data' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ env.DATA_NAME }} | |
| path: ${{ env.DATA_PATH }} | |
| outputs: | |
| INPUT_VERSION: ${{ needs.version.outputs.INPUT_VERSION }} | |
| SELECTED_VERSION: ${{ needs.version.outputs.SELECTED_VERSION }} | |
| LATEST_RELEASE: ${{ needs.version.outputs.LATEST_RELEASE }} | |
| LATEST_SNAPSHOT: ${{ needs.version.outputs.LATEST_SNAPSHOT }} | |
| generate-new-reports: | |
| name: "Generate new reports" | |
| runs-on: ubuntu-24.04 | |
| needs: [version] | |
| if: needs.version.outputs.TAG_EXISTS == 'FALSE' | |
| env: | |
| SELECTED_VERSION: ${{ needs.version.outputs.SELECTED_VERSION }} | |
| LATEST_SNAPSHOT: ${{ needs.version.outputs.LATEST_SNAPSHOT }} | |
| steps: | |
| - name: 'Generate reports for version "${{ env.SELECTED_VERSION }}" to "${{ env.REPORTS_PATH }}"' | |
| id: 'generate_reports' | |
| uses: MinecraftPlayground/generate-reports@main | |
| with: | |
| version: ${{ env.SELECTED_VERSION }} | |
| path: ${{ env.REPORTS_PATH }} | |
| - name: 'Check for generated reports' | |
| id: 'check_for_generated_reports' | |
| run: | | |
| if [ -z "$( ls -A $REPORTS_PATH )" ]; then | |
| echo "No reports found. Skipping reports jobs." | |
| echo "REPORTS_EXISTS=FALSE" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "Reports found. Running reports jobs." | |
| echo "REPORTS_EXISTS=TRUE" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: 'Upload generated reports' | |
| if: steps.check_for_generated_reports.outputs.REPORTS_EXISTS == 'TRUE' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ env.REPORTS_NAME }} | |
| path: ${{ env.REPORTS_PATH }} | |
| outputs: | |
| REPORTS_EXISTS: ${{ steps.check_for_generated_reports.outputs.REPORTS_EXISTS }} | |
| commit-and-tag-new-data: | |
| name: 'Commit and tag new data' | |
| runs-on: ubuntu-24.04 | |
| needs: ['generate-new-data', 'generate-new-reports'] | |
| env: | |
| SELECTED_VERSION: ${{ needs.generate-new-data.outputs.SELECTED_VERSION }} | |
| LATEST_RELEASE: ${{ needs.generate-new-data.outputs.LATEST_RELEASE }} | |
| LATEST_SNAPSHOT: ${{ needs.generate-new-data.outputs.LATEST_SNAPSHOT }} | |
| REPORTS_EXISTS: ${{ needs.generate-new-reports.outputs.REPORTS_EXISTS }} | |
| steps: | |
| - name: 'Generate GitHub App token' | |
| id: 'app-token' | |
| uses: actions/create-github-app-token@v1 | |
| with: | |
| app-id: ${{ secrets.APP_ID }} | |
| private-key: ${{ secrets.APP_PRIVATE_KEY }} | |
| - name: 'Configure GIT' | |
| run: | | |
| git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]' | |
| git config --global user.email '${{ secrets.APP_USER_ID }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com' | |
| - name: 'Checkout repository' | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ steps.app-token.outputs.token }} | |
| ref: ${{ env.GENERATED_BRANCH }} | |
| - name: 'Remove old data' | |
| run: | | |
| git rm -rf --ignore-unmatch "./" | |
| - name: 'Download generated data' | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: ${{ env.DATA_NAME }} | |
| path: './' | |
| - name: 'Download generated reports' | |
| if: env.REPORTS_EXISTS == 'TRUE' | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: ${{ env.REPORTS_NAME }} | |
| path: './reports' | |
| - name: 'Commit and push data' | |
| env: | |
| GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
| run: | | |
| COMMIT_MESSAGE="New data for version $SELECTED_VERSION" | |
| TAG="${SELECTED_VERSION// /_}" | |
| TAG_MESSAGE="Version $SELECTED_VERSION" | |
| echo "Commit Message: \"$COMMIT_MESSAGE\"" | |
| echo "Tag: \"$TAG\"" | |
| echo "Tag Message: \"$TAG_MESSAGE\"" | |
| git add -A | |
| if git diff --cached --quiet; then | |
| echo "No changes to commit." | |
| else | |
| git commit -m "$COMMIT_MESSAGE" | |
| fi | |
| git tag -fa "$TAG" -m "$TAG_MESSAGE" | |
| git push origin $GENERATED_BRANCH --tags | |
| - name: 'Update latest tags' | |
| env: | |
| GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
| run: | | |
| echo "Checking if $SELECTED_VERSION is latest release or snapshot..." | |
| # Latest release | |
| if [ "$SELECTED_VERSION" = "$LATEST_RELEASE" ]; then | |
| echo "Updating \"latest-release\" tag to point to \"$SELECTED_VERSION\"" | |
| git tag -f latest-release | |
| git push origin refs/tags/latest-release --force | |
| fi | |
| # Latest snapshot | |
| if [ "$SELECTED_VERSION" = "$LATEST_SNAPSHOT" ]; then | |
| echo "Updating \"latest-snapshot\" tag to point to \"$SELECTED_VERSION\"" | |
| git tag -f latest-snapshot | |
| git push origin refs/tags/latest-snapshot --force | |
| fi | |
| outputs: | |
| LATEST_RELEASE: ${{ needs.generate-new-data.outputs.LATEST_RELEASE }} | |
| LATEST_SNAPSHOT: ${{ needs.generate-new-data.outputs.LATEST_SNAPSHOT }} | |
| generate-badges: | |
| name: 'Generate badge' | |
| needs: ['commit-and-tag-new-data'] | |
| runs-on: ubuntu-24.04 | |
| env: | |
| LATEST_RELEASE: ${{ needs.commit-and-tag-new-data.outputs.LATEST_RELEASE }} | |
| LATEST_SNAPSHOT: ${{ needs.commit-and-tag-new-data.outputs.LATEST_SNAPSHOT }} | |
| steps: | |
| - name: 'Generate GitHub App token' | |
| id: 'app-token' | |
| uses: actions/create-github-app-token@v1 | |
| with: | |
| app-id: ${{ secrets.APP_ID }} | |
| private-key: ${{ secrets.APP_PRIVATE_KEY }} | |
| - name: 'Configure GIT' | |
| run: | | |
| git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]' | |
| git config --global user.email '${{ secrets.APP_USER_ID }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com' | |
| - name: 'Checkout repository' | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ steps.app-token.outputs.token }} | |
| ref: ${{ env.BADGE_BRANCH }} | |
| - name: 'Generate Badge (latest release)' | |
| id: 'generate-badge-latest-release' | |
| uses: loat-dev/action-badge@v1 | |
| with: | |
| icon: 'tag' | |
| label-text: 'Latest Release' | |
| state-text: ${{ env.LATEST_RELEASE }} | |
| - name: 'Generate Badge (latest snapshot)' | |
| id: 'generate-badge-latest-snapshot' | |
| uses: loat-dev/action-badge@v1 | |
| with: | |
| icon: 'tag' | |
| label-text: 'Latest Snapshot' | |
| state-text: ${{ env.LATEST_SNAPSHOT }} | |
| - name: 'Generate Badge (latest snapshot)' | |
| id: 'generate-badge-compare' | |
| uses: loat-dev/action-badge@v1 | |
| with: | |
| icon: 'git-compare' | |
| label-text: 'Compare' | |
| state-text: '${{ env.LATEST_RELEASE }} ... ${{ env.LATEST_SNAPSHOT }}' | |
| - name: 'Commit and push badge' | |
| env: | |
| GH_TOKEN: ${{ steps.app-token.outputs.token }} | |
| BADGE_FILE_LATEST_RELEASE: 'latest_release.svg' | |
| BADGE_FILE_LATEST_SNAPSHOT: 'latest_snapshot.svg' | |
| BADGE_FILE_COMPARE: 'compare.svg' | |
| run: | | |
| echo -e '${{ steps.generate-badge-latest-release.outputs.svg-text }}' > $BADGE_FILE_LATEST_RELEASE | |
| echo -e '${{ steps.generate-badge-latest-snapshot.outputs.svg-text }}' > $BADGE_FILE_LATEST_SNAPSHOT | |
| echo -e '${{ steps.generate-badge-compare.outputs.svg-text }}' > $BADGE_FILE_COMPARE | |
| COMMIT_MESSAGE="Update badges" | |
| echo "Commit Message: \"$COMMIT_MESSAGE\"" | |
| git add -A | |
| if git diff --cached --quiet; then | |
| echo "No changes to commit." | |
| else | |
| git commit -m "$COMMIT_MESSAGE" | |
| fi | |
| git push origin $BADGE_BRANCH |