From e593b4adb928fc3815de2deade87e0c1d1d093e2 Mon Sep 17 00:00:00 2001 From: Andreas Abel Date: Sat, 26 Nov 2022 17:24:52 +0100 Subject: [PATCH] CI: use actions `create-release` and `upload-release-asset` (#41) Restructure binary release logic to avoid races: 1. Prepare release with `create-release` and propagate upload URL to following step. 2. Build binaries and upload them to the previously created URL. Flaw in the ointment: action `upload-release-asset` is archived in favor of `softprops/action-gh-release`. However, I don't see how to use the latter without an extra artifact upload/download step, which seems stupid. --- .github/workflows/haskell-ci.yml | 16 +-- .github/workflows/stack.yml | 201 +++++++++++++++++++++++-------- fix-whitespace.cabal | 6 +- stack-9.2.4.yaml | 5 +- stack-9.2.5.yaml | 3 + stack-9.4.3.yaml | 3 + 6 files changed, 167 insertions(+), 67 deletions(-) create mode 100644 stack-9.2.5.yaml create mode 100644 stack-9.4.3.yaml diff --git a/.github/workflows/haskell-ci.yml b/.github/workflows/haskell-ci.yml index be62bc7..3896a76 100644 --- a/.github/workflows/haskell-ci.yml +++ b/.github/workflows/haskell-ci.yml @@ -8,9 +8,9 @@ # # For more information, see https://github.com/haskell-CI/haskell-ci # -# version: 0.15.20220920 +# version: 0.15.202211107 # -# REGENDATA ("0.15.20220920",["github","fix-whitespace.cabal"]) +# REGENDATA ("0.15.202211107",["github","fix-whitespace.cabal"]) # name: Haskell-CI on: @@ -34,14 +34,14 @@ jobs: strategy: matrix: include: - - compiler: ghc-9.4.2 + - compiler: ghc-9.4.3 compilerKind: ghc - compilerVersion: 9.4.2 + compilerVersion: 9.4.3 setup-method: ghcup allow-failure: false - - compiler: ghc-9.2.4 + - compiler: ghc-9.2.5 compilerKind: ghc - compilerVersion: 9.2.4 + compilerVersion: 9.2.5 setup-method: ghcup allow-failure: false - compiler: ghc-9.0.2 @@ -181,7 +181,7 @@ jobs: chmod a+x $HOME/.cabal/bin/cabal-plan cabal-plan --version - name: checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: path: source - name: initial cabal.project for sdist @@ -217,7 +217,7 @@ jobs: $CABAL v2-build $ARG_COMPILER $ARG_TESTS $ARG_BENCH --dry-run all cabal-plan - name: cache - uses: actions/cache@v2 + uses: actions/cache@v3 with: key: ${{ runner.os }}-${{ matrix.compiler }}-${{ github.sha }} path: ~/.cabal/store diff --git a/.github/workflows/stack.yml b/.github/workflows/stack.yml index 7d33e67..70f972f 100644 --- a/.github/workflows/stack.yml +++ b/.github/workflows/stack.yml @@ -18,17 +18,67 @@ permissions: contents: write jobs: - check: + + ## Release preparation + ########################################################################## + + # From: https://github.com/RobLoach/node-raylib/blob/aca2956e9ed283e5e91b1c8f08fafd943b5d6344/.github/workflows/release.yml + create_release: + runs-on: ubuntu-latest + outputs: + upload_url: ${{ steps.create_release.outputs.upload_url }} + steps: + + - uses: actions/checkout@v3 + if: startsWith(github.ref, 'refs/tags/v') + + - name: Create release + if: startsWith(github.ref, 'refs/tags/v') + id: create_release + uses: actions/create-release@v1 + with: + draft: false + prerelease: false + release_name: fix-whitespace ${{ github.ref }} + tag_name: ${{ github.ref }} + # body: fix-whitespace binary release created from ${{ github.ref }} + env: + GITHUB_TOKEN: ${{ github.token }} + + - name: Source tarball creation. + # Conditional to ensure this deployment is only run once per action. + if: startsWith(github.ref, 'refs/tags/v') + run: | + cabal sdist + export DIST_TGZ_PATH=$(cabal sdist | tail -1) + export DIST_TGZ_NAME=$(basename "${DIST_TGZ_PATH}") + echo "DIST_TGZ_PATH=${DIST_TGZ_PATH}" >> ${GITHUB_ENV} + echo "DIST_TGZ_NAME=${DIST_TGZ_NAME}" >> ${GITHUB_ENV} + + - name: Source tarball release. + if: startsWith(github.ref, 'refs/tags/v') + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ${{ env.DIST_TGZ_PATH }} + asset_name: ${{ env.DIST_TGZ_NAME }} + asset_content_type: application/octet-stream + + + build: runs-on: ${{ matrix.os }} + needs: create_release strategy: matrix: os: [ubuntu-20.04] - ghc-ver: [9.2.4, 9.0.2, 8.10.7, 8.8.4, 8.6.5, 8.4.4, 8.2.2, 8.0.2] + ghc-ver: [9.4.3, 9.2.5, 9.0.2, 8.10.7, 8.8.4, 8.6.5, 8.4.4, 8.2.2, 8.0.2] include: - os: windows-2022 ghc-ver: 9.2.4 - os: macos-11 - ghc-ver: 9.2.4 + ghc-ver: 9.2.5 fail-fast: false env: @@ -90,49 +140,65 @@ jobs: ## Release ######################################################################## - - name: Source tarball creation. - # Conditional to ensure this deployment is only run once per action. - if: >- - startsWith(github.ref, 'refs/tags/v') - && matrix.ghc-ver == '9.2.4' - run: | - export DIST_TGZ=$(cabal sdist source | tail -1) - echo "DIST_TGZ=${DIST_TGZ}" >> ${GITHUB_ENV} + # - name: Source tarball creation. + # # Conditional to ensure this deployment is only run once per action. + # if: >- + # startsWith(github.ref, 'refs/tags/v') + # && matrix.ghc-ver == '9.2.5' + # run: | + # export DIST_TGZ=$(cabal sdist | tail -1) + # echo "DIST_TGZ=${DIST_TGZ}" >> ${GITHUB_ENV} - - name: Source tarball release. - if: >- - startsWith(github.ref, 'refs/tags/v') - && matrix.ghc-ver == '9.2.4' - uses: softprops/action-gh-release@v1 - with: - draft: true - prerelease: true - files: | - ${{ env.DIST_TGZ }} + # - name: Source tarball release. + # if: >- + # startsWith(github.ref, 'refs/tags/v') + # && matrix.ghc-ver == '9.2.5' + # # uses: softprops/action-gh-release@v1 + # # with: + # # draft: true + # # prerelease: true + # # files: | + # # ${{ env.DIST_TGZ }} + # uses: actions/upload-release-asset@v1 + # env: + # GITHUB_TOKEN: ${{ github.token }} + # with: + # upload_url: ${{ needs.create_release.outputs.upload_url }} + # asset_path: ${{ env.DIST_TGZ }} + # asset_name: ${{ env.DIST_TGZ }} + # asset_content_type: application/octet-stream - name: Linux release preparation. if: >- startsWith(github.ref, 'refs/tags/v') && runner.os == 'Linux' - && matrix.ghc-ver == '9.2.4' + && matrix.ghc-ver == '9.2.5' run: | export FIXW_BIN=fix-whitespace-${FIXW_VERSION}-linux.binary cp -p ${FIXW_EXE} ${FIXW_BIN} # Save env variables for the next step echo "FIXW_BIN=${FIXW_BIN}" >> ${GITHUB_ENV} - - name: Linux release. - if: >- - startsWith(github.ref, 'refs/tags/v') - && runner.os == 'Linux' - && matrix.ghc-ver == '9.2.4' - uses: softprops/action-gh-release@v1 - with: - draft: true - prerelease: true - files: | - ${{ env.FIXW_BIN }} + # - name: Linux release. + # if: >- + # startsWith(github.ref, 'refs/tags/v') + # && runner.os == 'Linux' + # && matrix.ghc-ver == '9.2.5' + # # uses: softprops/action-gh-release@v1 + # # with: + # # draft: true + # # prerelease: true + # # files: | + # # ${{ env.FIXW_BIN }} + # uses: actions/upload-release-asset@v1 + # env: + # GITHUB_TOKEN: ${{ github.token }} + # with: + # upload_url: ${{ needs.create_release.outputs.upload_url }} + # asset_path: ${{ env.FIXW_BIN }} + # asset_name: ${{ env.FIXW_BIN }} + # asset_content_type: application/octet-stream - name: Mac release preparation. @@ -146,16 +212,24 @@ jobs: # Save env variables for the next step echo "FIXW_BIN=${FIXW_BIN}" >> ${GITHUB_ENV} - - name: Mac release. - if: >- - startsWith(github.ref, 'refs/tags/v') - && runner.os == 'macOS' - uses: softprops/action-gh-release@v1 - with: - draft: true - prerelease: true - files: | - ${{ env.FIXW_BIN }} + # - name: Mac release. + # if: >- + # startsWith(github.ref, 'refs/tags/v') + # && runner.os == 'macOS' + # # uses: softprops/action-gh-release@v1 + # # with: + # # draft: true + # # prerelease: true + # # files: | + # # ${{ env.FIXW_BIN }} + # uses: actions/upload-release-asset@v1 + # env: + # GITHUB_TOKEN: ${{ github.token }} + # with: + # upload_url: ${{ needs.create_release.outputs.upload_url }} + # asset_path: ${{ env.FIXW_BIN }} + # asset_name: ${{ env.FIXW_BIN }} + # asset_content_type: application/octet-stream - name: Windows release preparation. @@ -164,18 +238,39 @@ jobs: && runner.os == 'Windows' shell: bash run: | - export FIXW_VER_EXE=fix-whitespace-${FIXW_VERSION}.exe - cp -p ${FIXW_EXE}.exe ${FIXW_VER_EXE} + export FIXW_BIN=fix-whitespace-${FIXW_VERSION}.exe + cp -p ${FIXW_EXE}.exe ${FIXW_BIN} # Save env variables for the next step - echo "FIXW_VER_EXE=${FIXW_VER_EXE}" >> ${GITHUB_ENV} + echo "FIXW_BIN=${FIXW_BIN}" >> ${GITHUB_ENV} - - name: Windows release. + # - name: Windows release. + # if: >- + # startsWith(github.ref, 'refs/tags/v') + # && runner.os == 'Windows' + # uses: actions/upload-release-asset@v1 + # env: + # GITHUB_TOKEN: ${{ github.token }} + # with: + # upload_url: ${{ needs.create_release.outputs.upload_url }} + # asset_path: ${{ env.FIXW_BIN }} + # asset_name: ${{ env.FIXW_BIN }} + # asset_content_type: application/octet-stream + # # uses: softprops/action-gh-release@v1 + # # with: + # # draft: true + # # prerelease: true + # # files: | + # # ${{ env.FIXW_VER_EXE }} + + - name: Upload binary. if: >- startsWith(github.ref, 'refs/tags/v') - && runner.os == 'Windows' - uses: softprops/action-gh-release@v1 + && (matrix.ghc-ver == '9.2.5' || !(runner.os == 'Linux')) + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ github.token }} with: - draft: true - prerelease: true - files: | - ${{ env.FIXW_VER_EXE }} + upload_url: ${{ needs.create_release.outputs.upload_url }} + asset_path: ${{ env.FIXW_BIN }} + asset_name: ${{ env.FIXW_BIN }} + asset_content_type: application/octet-stream diff --git a/fix-whitespace.cabal b/fix-whitespace.cabal index 403bb18..d817411 100644 --- a/fix-whitespace.cabal +++ b/fix-whitespace.cabal @@ -13,8 +13,8 @@ maintainer: Liang-Ting Chen , Andreas Abel Category: Text Synopsis: Fixes whitespace issues. tested-with: - GHC == 9.4.2 - GHC == 9.2.4 + GHC == 9.4.3 + GHC == 9.2.5 GHC == 9.0.2 GHC == 8.10.7 GHC == 8.8.4 @@ -35,6 +35,8 @@ extra-source-files: stack-8.10.7.yaml stack-9.0.2.yaml stack-9.2.4.yaml + stack-9.2.5.yaml + stack-9.4.3.yaml source-repository head type: git diff --git a/stack-9.2.4.yaml b/stack-9.2.4.yaml index a0a2b13..51c2a1a 100644 --- a/stack-9.2.4.yaml +++ b/stack-9.2.4.yaml @@ -1,6 +1,3 @@ -resolver: nightly-2022-08-19 +resolver: nightly-2022-11-12 compiler: ghc-9.2.4 compiler-check: match-exact - -extra-deps: - - filepattern-0.1.3 diff --git a/stack-9.2.5.yaml b/stack-9.2.5.yaml new file mode 100644 index 0000000..378fc3a --- /dev/null +++ b/stack-9.2.5.yaml @@ -0,0 +1,3 @@ +resolver: lts-20.1 +compiler: ghc-9.2.5 +compiler-check: match-exact diff --git a/stack-9.4.3.yaml b/stack-9.4.3.yaml new file mode 100644 index 0000000..00eeebc --- /dev/null +++ b/stack-9.4.3.yaml @@ -0,0 +1,3 @@ +resolver: nightly-2022-11-26 +compiler: ghc-9.4.3 +compiler-check: match-exact