From 2e444cee296805239b2322750101bd59b8be2a18 Mon Sep 17 00:00:00 2001 From: Luke Bemish Date: Sat, 6 Jan 2024 16:31:36 -0600 Subject: [PATCH] Generate actions --- .github/workflows/build_pr.yml | 69 +++++++++++++++ .github/workflows/publish_pr.yml | 56 ++++++++++++ .github/workflows/pullrequest.yml | 51 ----------- .github/workflows/release.yml | 140 +++++++++++++++++++++--------- .github/workflows/snapshot.yml | 117 ++++++++++++++++--------- .github/workflows/test.yml | 41 --------- 6 files changed, 298 insertions(+), 176 deletions(-) create mode 100644 .github/workflows/build_pr.yml create mode 100644 .github/workflows/publish_pr.yml delete mode 100644 .github/workflows/pullrequest.yml delete mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/build_pr.yml b/.github/workflows/build_pr.yml new file mode 100644 index 0000000..ed01916 --- /dev/null +++ b/.github/workflows/build_pr.yml @@ -0,0 +1,69 @@ +{ + "jobs": { + "build": { + "runs-on": "ubuntu-22.04", + "steps": [ + { + "name": "Setup Java", + "run": "echo \"JAVA_HOME=$JAVA_HOME_17_X64\" >> \"$GITHUB_ENV\"" + }, + { + "with": { + "fetch-depth": "0", + "persist-credentials": "false" + }, + "name": "Checkout", + "uses": "actions/checkout@v4" + }, + { + "with": { + "path": "**/.gradle/loom-cache", + "key": "${{ runner.os }}-gradle-${{ hashFiles('**/libs.versions.*', '**/*.gradle*', '**/gradle-wrapper.properties') }}", + "restore-keys": "${{ runner.os }}-gradle-" + }, + "name": "Cache", + "uses": "actions/cache/restore@v3" + }, + { + "with": { + "cache-read-only": true, + "gradle-home-cache-cleanup": true + }, + "name": "Setup Gradle", + "uses": "gradle/gradle-build-action@v2" + }, + { + "name": "Build", + "run": "./gradlew checkLicenses build", + "id": "build", + "env": { + "PR_NUMBER": "${{ github.event.pull_request.number }}" + } + }, + { + "name": "Publish", + "run": "./gradlew publish", + "id": "publish", + "env": { + "PR_NUMBER": "${{ github.event.pull_request.number }}" + } + }, + { + "with": { + "name": "artifacts", + "path": "build/repo" + }, + "name": "Archive Publishable Artifacts", + "uses": "actions/upload-artifact@v4" + } + ] + } + }, + "name": "Build PR", + "concurrency": "ci-${{ github.ref }}", + "on": { + "pull_request": { + + } + } +} \ No newline at end of file diff --git a/.github/workflows/publish_pr.yml b/.github/workflows/publish_pr.yml new file mode 100644 index 0000000..94e42ec --- /dev/null +++ b/.github/workflows/publish_pr.yml @@ -0,0 +1,56 @@ +{ + "jobs": { + "publish": { + "runs-on": "ubuntu-22.04", + "steps": [ + { + "with": { + "repository": "lukebemish/artifact-sync", + "ref": "refs/heads/main", + "persist-credentials": false + }, + "name": "Checkout Artifact Sync", + "uses": "actions/checkout@v4" + }, + { + "run": "mkdir repo" + }, + { + "with": { + "script": "const pull_requests = ${{ toJSON(github.event.workflow_run.pull_requests) }};\nif (!pull_requests.length) {\n return core.error(\"This workflow doesn't match any pull requests!\");\n}\nlet allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({\n owner: context.repo.owner,\n repo: context.repo.repo,\n run_id: context.payload.workflow_run.id,\n});\nlet matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {\n return artifact.name == \"artifacts\"\n})[0];\nlet download = await github.rest.actions.downloadArtifact({\n owner: context.repo.owner,\n repo: context.repo.repo,\n artifact_id: matchArtifact.id,\n archive_format: 'zip',\n});\nlet fs = require('fs');\nfs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/repo.zip`, Buffer.from(download.data));" + }, + "name": "Download Artifacts", + "uses": "actions/github-script@v7" + }, + { + "name": "Unpack Artifacts", + "run": "unzip repo.zip -d repo" + }, + { + "name": "Publish Artifacts", + "run": "python3 run.py", + "env": { + "MAVEN_USER": "github", + "MAVEN_PASSWORD": "${{ secrets.PR_MAVEN_PASSWORD }}", + "MAVEN_URL": "https://maven.lukebemish.dev/pullrequests/", + "ALLOWED_VERSION": "*-pr${{ github.event.workflow_run.pull_requests[0].number }}", + "ALLOWED_PATHS": "dev/lukebemish/dynamicassetgenerator/dynamicassetgenerator-*" + } + } + ], + "if": "${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }}" + } + }, + "name": "Publish PR", + "concurrency": "ci-${{ github.ref }}", + "on": { + "workflow_run": { + "workflows": [ + "Build PR" + ], + "types": [ + "completed" + ] + } + } +} \ No newline at end of file diff --git a/.github/workflows/pullrequest.yml b/.github/workflows/pullrequest.yml deleted file mode 100644 index 9a90d8d..0000000 --- a/.github/workflows/pullrequest.yml +++ /dev/null @@ -1,51 +0,0 @@ -name: Publish PR -on: - workflow_run: - workflows: [Test] - types: [completed] -jobs: - publish: - runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success' }} - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - repository: lukebemish/artifact-sync - ref: refs/heads/main - - run: mkdir repo - - name: 'Download artifact' - uses: actions/github-script@v6 - with: - script: | - const pull_requests = ${{ toJSON(github.event.workflow_run.pull_requests) }}; - if (!pull_requests.length) { - return core.error("This workflow doesn't match any pull requests!"); - } - - let allArtifacts = await github.rest.actions.listWorkflowRunArtifacts({ - owner: context.repo.owner, - repo: context.repo.repo, - run_id: context.payload.workflow_run.id, - }); - let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => { - return artifact.name == "artifacts" - })[0]; - let download = await github.rest.actions.downloadArtifact({ - owner: context.repo.owner, - repo: context.repo.repo, - artifact_id: matchArtifact.id, - archive_format: 'zip', - }); - let fs = require('fs'); - fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/repo.zip`, Buffer.from(download.data)); - - name: 'Unzip artifacts' - run: unzip repo.zip -d repo - - name: 'Publish artifacts' - run: python3 run.py - env: - MAVEN_USER: github - MAVEN_PASSWORD: ${{ secrets.PR_MAVEN_PASSWORD }} - MAVEN_URL: "https://maven.lukebemish.dev/pullrequests/" - ALLOWED_VERSION: '*-pr${{ github.event.workflow_run.pull_requests[0].number }}' - ALLOWED_PATHS: "dev/lukebemish/excavatedvariants/excavatedvariants-*" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f6999b0..49d9eac 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,43 +1,97 @@ -name: Release -concurrency: ci-${{ github.ref }} -on: - workflow_dispatch: -jobs: - build: - runs-on: ubuntu-22.04 - steps: - - name: Setup Java - run: | - echo "JAVA_HOME=$JAVA_HOME_17_X64" >> "$GITHUB_ENV" - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - uses: fregante/setup-git-user@v2 - - uses: actions/cache@v3 - with: - path: | - **/.gradle/loom-cache - key: ${{ runner.os }}-gradle-${{ hashFiles('**/libs.versions.*', '**/*.gradle*', '**/gradle-wrapper.properties') }} - restore-keys: ${{ runner.os }}-gradle- - - uses: gradle/gradle-build-action@v2 - name: Setup Gradle - with: - gradle-home-cache-cleanup: true - - name: Tag Release - run: | - ./gradlew tagRelease - - name: Build - run: | - ./gradlew checkLicenses build - - name: Publish - run: | - ./gradlew publish curseforge modrinth - env: - MAVEN_USER: github - MAVEN_PASSWORD: ${{ secrets.RELEASE_MAVEN_PASSWORD }} - CURSEFORGE_KEY: ${{ secrets.CURSEFORGE_KEY }} - MODRINTH_KEY: ${{ secrets.MODRINTH_KEY }} - MAVEN_URL: https://maven.lukebemish.dev/releases/ - - run: | - git push - git push --tags +{ + "jobs": { + "build": { + "runs-on": "ubuntu-22.04", + "permissions": { + "contents": "write" + }, + "steps": [ + { + "name": "Setup Java", + "run": "echo \"JAVA_HOME=$JAVA_HOME_17_X64\" >> \"$GITHUB_ENV\"" + }, + { + "with": { + "fetch-depth": "0" + }, + "name": "Checkout", + "uses": "actions/checkout@v4" + }, + { + "with": { + "path": "**/.gradle/loom-cache", + "key": "${{ runner.os }}-gradle-${{ hashFiles('**/libs.versions.*', '**/*.gradle*', '**/gradle-wrapper.properties') }}", + "restore-keys": "${{ runner.os }}-gradle-" + }, + "name": "Cache", + "uses": "actions/cache@v3" + }, + { + "with": { + "gradle-home-cache-cleanup": true + }, + "name": "Setup Gradle", + "uses": "gradle/gradle-build-action@v2" + }, + { + "uses": "fregante/setup-git-user@v2" + }, + { + "name": "Tag Release", + "run": "./gradlew tagRelease", + "id": "tag_release", + "env": { + "BUILD_CACHE_PASSWORD": "${{ secrets.BUILD_CACHE_PASSWORD }}", + "BUILD_CACHE_USER": "${{ secrets.BUILD_CACHE_USER }}", + "BUILD_CACHE_URL": "${{ secrets.BUILD_CACHE_URL }}", + "RELEASE_MAVEN_PASSWORD": "${{ secrets.RELEASE_MAVEN_PASSWORD }}", + "RELEASE_MAVEN_USER": "github", + "RELEASE_MAVEN_URL": "https://maven.lukebemish.dev/releases/", + "CURSEFORGE_KEY": "${{ secrets.CURSEFORGE_KEY }}", + "MODRINTH_KEY": "${{ secrets.MODRINTH_KEY }}" + } + }, + { + "name": "Build", + "run": "./gradlew checkLicenses build", + "id": "build", + "env": { + "BUILD_CACHE_PASSWORD": "${{ secrets.BUILD_CACHE_PASSWORD }}", + "BUILD_CACHE_USER": "${{ secrets.BUILD_CACHE_USER }}", + "BUILD_CACHE_URL": "${{ secrets.BUILD_CACHE_URL }}", + "RELEASE_MAVEN_PASSWORD": "${{ secrets.RELEASE_MAVEN_PASSWORD }}", + "RELEASE_MAVEN_USER": "github", + "RELEASE_MAVEN_URL": "https://maven.lukebemish.dev/releases/", + "CURSEFORGE_KEY": "${{ secrets.CURSEFORGE_KEY }}", + "MODRINTH_KEY": "${{ secrets.MODRINTH_KEY }}" + } + }, + { + "run": "git push && git push --tags" + }, + { + "name": "Publish", + "run": "./gradlew publish modrinth curseforge", + "id": "publish", + "env": { + "BUILD_CACHE_PASSWORD": "${{ secrets.BUILD_CACHE_PASSWORD }}", + "BUILD_CACHE_USER": "${{ secrets.BUILD_CACHE_USER }}", + "BUILD_CACHE_URL": "${{ secrets.BUILD_CACHE_URL }}", + "RELEASE_MAVEN_PASSWORD": "${{ secrets.RELEASE_MAVEN_PASSWORD }}", + "RELEASE_MAVEN_USER": "github", + "RELEASE_MAVEN_URL": "https://maven.lukebemish.dev/releases/", + "CURSEFORGE_KEY": "${{ secrets.CURSEFORGE_KEY }}", + "MODRINTH_KEY": "${{ secrets.MODRINTH_KEY }}" + } + } + ] + } + }, + "name": "Release", + "concurrency": "ci-${{ github.ref }}", + "on": { + "workflow_dispatch": { + + } + } +} \ No newline at end of file diff --git a/.github/workflows/snapshot.yml b/.github/workflows/snapshot.yml index dc8fcfd..f86329a 100644 --- a/.github/workflows/snapshot.yml +++ b/.github/workflows/snapshot.yml @@ -1,41 +1,76 @@ -name: Snapshot -concurrency: ci-${{ github.ref }} -on: - workflow_dispatch: - push: - branches: - - 1.* -jobs: - build: - runs-on: ubuntu-22.04 - steps: - - name: Setup Java - run: | - echo "JAVA_HOME=$JAVA_HOME_17_X64" >> "$GITHUB_ENV" - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - uses: fregante/setup-git-user@v2 - - uses: actions/cache@v3 - with: - path: | - **/.gradle/loom-cache - key: ${{ runner.os }}-gradle-${{ hashFiles('**/libs.versions.*', '**/*.gradle*', '**/gradle-wrapper.properties') }} - restore-keys: ${{ runner.os }}-gradle- - - uses: gradle/gradle-build-action@v2 - name: Setup Gradle - with: - gradle-home-cache-cleanup: true - - name: Build - id: build - run: | - ./gradlew checkLicenses build - env: - SNAPSHOT_MAVEN_URL: https://maven.lukebemish.dev/snapshots/ - - name: Publish - run: | - ./gradlew publish - env: - MAVEN_USER: github - MAVEN_PASSWORD: ${{ secrets.SNAPSHOT_MAVEN_PASSWORD }} - SNAPSHOT_MAVEN_URL: https://maven.lukebemish.dev/snapshots/ +{ + "jobs": { + "build": { + "runs-on": "ubuntu-22.04", + "steps": [ + { + "name": "Setup Java", + "run": "echo \"JAVA_HOME=$JAVA_HOME_17_X64\" >> \"$GITHUB_ENV\"" + }, + { + "with": { + "fetch-depth": "0", + "persist-credentials": "false" + }, + "name": "Checkout", + "uses": "actions/checkout@v4" + }, + { + "with": { + "path": "**/.gradle/loom-cache", + "key": "${{ runner.os }}-gradle-${{ hashFiles('**/libs.versions.*', '**/*.gradle*', '**/gradle-wrapper.properties') }}", + "restore-keys": "${{ runner.os }}-gradle-" + }, + "name": "Cache", + "uses": "actions/cache/restore@v3" + }, + { + "with": { + "cache-read-only": true, + "gradle-home-cache-cleanup": true + }, + "name": "Setup Gradle", + "uses": "gradle/gradle-build-action@v2" + }, + { + "name": "Build", + "run": "./gradlew checkLicenses build", + "id": "build", + "env": { + "BUILD_CACHE_PASSWORD": "${{ secrets.BUILD_CACHE_PASSWORD }}", + "BUILD_CACHE_USER": "${{ secrets.BUILD_CACHE_USER }}", + "BUILD_CACHE_URL": "${{ secrets.BUILD_CACHE_URL }}", + "SNAPSHOT_MAVEN_PASSWORD": "${{ secrets.SNAPSHOT_MAVEN_PASSWORD }}", + "SNAPSHOT_MAVEN_USER": "github", + "SNAPSHOT_MAVEN_URL": "https://maven.lukebemish.dev/snapshots/" + } + }, + { + "name": "Publish", + "run": "./gradlew publish", + "id": "publish", + "env": { + "BUILD_CACHE_PASSWORD": "${{ secrets.BUILD_CACHE_PASSWORD }}", + "BUILD_CACHE_USER": "${{ secrets.BUILD_CACHE_USER }}", + "BUILD_CACHE_URL": "${{ secrets.BUILD_CACHE_URL }}", + "SNAPSHOT_MAVEN_PASSWORD": "${{ secrets.SNAPSHOT_MAVEN_PASSWORD }}", + "SNAPSHOT_MAVEN_USER": "github", + "SNAPSHOT_MAVEN_URL": "https://maven.lukebemish.dev/snapshots/" + } + } + ] + } + }, + "name": "Snapshot", + "concurrency": "ci-${{ github.ref }}", + "on": { + "workflow_dispatch": { + + }, + "push": { + "branches": [ + "1.*" + ] + } + } +} \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 10722be..0000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Test -concurrency: ci-${{ github.ref }} -on: [workflow_dispatch, pull_request] -jobs: - build: - runs-on: ubuntu-22.04 - steps: - - name: Setup Java - run: | - echo "JAVA_HOME=$JAVA_HOME_17_X64" >> "$GITHUB_ENV" - - uses: actions/checkout@v4 - with: - persist-credentials: false - fetch-depth: 0 - - uses: fregante/setup-git-user@v2 - - uses: actions/cache/restore@v3 - with: - path: | - **/.gradle/loom-cache - key: ${{ runner.os }}-gradle-${{ hashFiles('**/libs.versions.*', '**/*.gradle*', '**/gradle-wrapper.properties') }} - restore-keys: ${{ runner.os }}-gradle- - - uses: gradle/gradle-build-action@v2 - name: Setup Gradle - with: - cache-read-only: true - gradle-home-cache-cleanup: true - - name: Build - run: | - ./gradlew checkLicenses build - env: - PR_NUMBER: ${{ github.event.pull_request.number }} - - name: Publish - run: | - ./gradlew publish - env: - PR_NUMBER: ${{ github.event.pull_request.number }} - - name: Archive publishable artifacts - uses: actions/upload-artifact@v3 - with: - name: artifacts - path: build/repo