From 3d4bed04d5816b58857f3260b8c775a326fb3a51 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 15 Mar 2023 08:13:33 -0400 Subject: [PATCH] Split up actions (#129) * Refactor conditional dependent jobs into separate actions * Fix incorrect usage of pull_request_target * Fix Dependabot not merging due to labels being absent when issue is created * Prettify supported version listing --- .github/workflows/automerge_dependabot.yml | 26 +++++++++ .github/workflows/ci.yml | 53 +------------------ .github/workflows/draft_release.yml | 44 +++++++++++++++ .../{release.yml => external_release.yml} | 0 scripts/generate_changelog.sh | 4 +- 5 files changed, 73 insertions(+), 54 deletions(-) create mode 100644 .github/workflows/automerge_dependabot.yml create mode 100644 .github/workflows/draft_release.yml rename .github/workflows/{release.yml => external_release.yml} (100%) diff --git a/.github/workflows/automerge_dependabot.yml b/.github/workflows/automerge_dependabot.yml new file mode 100644 index 0000000..94083be --- /dev/null +++ b/.github/workflows/automerge_dependabot.yml @@ -0,0 +1,26 @@ +name: Auto-merge Dependabot PRs + +on: + workflow_run: + workflows: [ "OpenInv CI" ] + types: [ completed ] + +jobs: + merge-dependabot: + if: "github.actor == 'dependabot[bot]' + && github.event.workflow_run.event == 'pull_request' + && github.event.workflow_run.conclusion == 'success'" + runs-on: ubuntu-latest + steps: + - name: Approve + uses: hmarr/auto-approve-action@v3.1.0 + with: + github-token: "${{ secrets.GITHUB_TOKEN }}" + pull-request-number: "${{ github.event.workflow_run.event.pull_request.id }}" + - name: Merge + uses: pascalgn/automerge-action@v0.15.6 + env: + GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" + MERGE_LABELS: "dependencies,java" + MERGE_METHOD: "squash" + PULL_REQUEST: "${{ github.event.workflow_run.event.pull_request.id }}" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e872fd0..62cbfa2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,7 @@ name: OpenInv CI on: push: - pull_request_target: + pull_request: jobs: build: @@ -36,54 +36,3 @@ jobs: with: name: api path: ./api/target/openinvapi*.jar - - merge-dependabot: - name: Auto-merge Dependabot PRs - needs: [ build ] - if: "github.event.name == 'pull_request_target' - && github.actor == 'dependabot[bot]' - && contains( github.event.pull_request.labels.*.name, 'java')" - runs-on: ubuntu-latest - steps: - - name: Approve - uses: hmarr/auto-approve-action@v3.1.0 - with: - github-token: "${{ secrets.GITHUB_TOKEN }}" - - name: Merge - uses: pascalgn/automerge-action@v0.15.6 - env: - GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}" - MERGE_LABELS: "dependencies" - MERGE_METHOD: "squash" - - release: - name: Create Github Release - needs: [ build ] - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') - runs-on: ubuntu-latest - steps: - # Fetch all history - used to assemble changelog. - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Set Release Variables - run: bash ./scripts/set_release_env.sh - - - name: Download Artifact - uses: actions/download-artifact@v3 - with: - name: dist - path: dist - - - name: Create Release - id: create-release - uses: softprops/action-gh-release@v0.1.15 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - name: ${{ env.VERSIONED_NAME }} - body: ${{ env.GENERATED_CHANGELOG }} - draft: true - prerelease: false - files: ./dist/OpenInv.jar diff --git a/.github/workflows/draft_release.yml b/.github/workflows/draft_release.yml new file mode 100644 index 0000000..a3ffdcd --- /dev/null +++ b/.github/workflows/draft_release.yml @@ -0,0 +1,44 @@ +name: Draft Github Release + +on: + workflow_run: + workflows: [ "OpenInv CI" ] + types: [ completed ] + +jobs: + draft_release: + if: "github.event.workflow_run.event == 'push' + && github.event.workflow_run.conclusion == 'success' + && startsWith(github.event.workflow_run.event.push.ref, 'refs/tags/')" + runs-on: ubuntu-latest + steps: + # Fetch all history - used to assemble changelog. + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set Release Variables + run: bash ./scripts/set_release_env.sh + + - name: Download Artifact + # Unfortunately actions/download-artifact cannot fetch from other workflow runs. + uses: dawidd6/action-download-artifact@v2.26.0 + with: + name: dist + path: dist + run_id: "${{ github.event.workflow_run.id }}" + run_number: "${{ github.event.workflow_run.run_number }}" + # Searching for a specific run ID that we know was successful, unset 'success' default. + workflow_conclusion: "" + + - name: Create Release + id: create-release + uses: softprops/action-gh-release@v0.1.15 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + name: ${{ env.VERSIONED_NAME }} + body: ${{ env.GENERATED_CHANGELOG }} + draft: true + prerelease: false + files: ./dist/OpenInv.jar diff --git a/.github/workflows/release.yml b/.github/workflows/external_release.yml similarity index 100% rename from .github/workflows/release.yml rename to .github/workflows/external_release.yml diff --git a/scripts/generate_changelog.sh b/scripts/generate_changelog.sh index d2261f1..bc234b9 100644 --- a/scripts/generate_changelog.sh +++ b/scripts/generate_changelog.sh @@ -1,6 +1,6 @@ #!/bin/bash # -# Copyright (C) 2011-2021 lishid. All rights reserved. +# Copyright (C) 2011-2023 lishid. All rights reserved. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -36,7 +36,7 @@ function get_minecraft_versions() { for version in "${versions[@]}"; do # Append comma if variable is set, then append version - minecraft_versions="${minecraft_versions:+${minecraft_versions},}${version%%-R*}" + minecraft_versions="${minecraft_versions:+${minecraft_versions}, }${version%%-R*}" done echo "${minecraft_versions}"