From e3618b939e119b8ae6d0dcea0f4077fe2c332122 Mon Sep 17 00:00:00 2001 From: ab77 Date: Mon, 7 Nov 2022 18:41:28 -0800 Subject: [PATCH] CI: generalise artefact handling * on PR syncs, delete draft releases on Linux runners only * delete draft releases when unmerged PRs are closed Change-type: patch --- .github/actions/always/action.yml | 38 ++++++++++++++++++++++++++++++ .github/actions/publish/action.yml | 17 ++----------- .github/actions/test/action.yml | 9 ++----- 3 files changed, 42 insertions(+), 22 deletions(-) create mode 100644 .github/actions/always/action.yml diff --git a/.github/actions/always/action.yml b/.github/actions/always/action.yml new file mode 100644 index 00000000..37e76413 --- /dev/null +++ b/.github/actions/always/action.yml @@ -0,0 +1,38 @@ +--- +name: cleanup +# https://github.com/product-os/flowzone/tree/master/.github/actions +inputs: + json: + description: "JSON stringified object containing all the inputs from the calling workflow" + required: true + secrets: + description: "JSON stringified object containing all the secrets from the calling workflow" + required: true + + # --- custom environment + VERBOSE: + type: string + default: "true" + +runs: + # https://docs.github.com/en/actions/creating-actions/creating-a-composite-action + using: "composite" + steps: + # delete draft releases if the pull request is closed without merging + - name: Delete draft release + if: | + runner.os == 'Linux' && + github.event_name == 'pull_request' && + github.event.pull_request.merged == false && + github.event.action == 'closed' + + shell: bash --noprofile --norc -eo pipefail -x {0} + run: | + set -ea + + [[ '${{ inputs.VERBOSE }}' =~ on|On|Yes|yes|true|True ]] && set -x + + gh release delete --yes '${{ github.event.pull_request.head.ref }}' || true + + env: + GITHUB_TOKEN: ${{ fromJSON(inputs.secrets).FLOWZONE_TOKEN }} diff --git a/.github/actions/publish/action.yml b/.github/actions/publish/action.yml index f134d51e..cd34179e 100644 --- a/.github/actions/publish/action.yml +++ b/.github/actions/publish/action.yml @@ -31,17 +31,10 @@ runs: path: ${{ runner.temp }} - name: Extract custom source artifact - if: runner.os != 'Windows' - shell: bash --noprofile --norc -eo pipefail -x {0} + shell: pwsh working-directory: . run: tar -xf ${{ runner.temp }}/custom.tgz - - name: Extract custom source artifact - if: runner.os == 'Windows' - shell: powershell - working-directory: . - run: tar -xf ${{ runner.temp }}\custom.tgz - - name: Setup Node.js uses: actions/setup-node@v3 with: @@ -233,15 +226,9 @@ runs: dist/latest*.yml - name: Compress custom source - if: runner.os != 'Windows' - shell: bash --noprofile --norc -eo pipefail -x {0} + shell: pwsh run: tar -acf ${{ runner.temp }}/custom.tgz . - - name: Compress custom source - if: runner.os == 'Windows' - shell: powershell - run: tar -acf ${{ runner.temp }}\custom.tgz . - - name: Upload custom artifact uses: actions/upload-artifact@v3 with: diff --git a/.github/actions/test/action.yml b/.github/actions/test/action.yml index 289f6b53..a1620a4e 100644 --- a/.github/actions/test/action.yml +++ b/.github/actions/test/action.yml @@ -22,6 +22,7 @@ runs: using: "composite" steps: - name: Delete previous draft release + if: runner.os == 'Linux' shell: bash --noprofile --norc -eo pipefail -x {0} run: | set -ea @@ -59,15 +60,9 @@ runs: ELECTRON_NO_ATTACH_CONSOLE: true - name: Compress custom source - if: runner.os != 'Windows' - shell: bash --noprofile --norc -eo pipefail -x {0} + shell: pwsh run: tar -acf ${{ runner.temp }}/custom.tgz . - - name: Compress custom source - if: runner.os == 'Windows' - shell: powershell - run: tar -acf ${{ runner.temp }}\custom.tgz . - - name: Upload custom artifact uses: actions/upload-artifact@v3 with: