From 36c582d2392c4e4e67f42457bd0ea75c9d66dd07 Mon Sep 17 00:00:00 2001 From: Leonhard Riedisser Date: Thu, 13 Jun 2024 11:48:31 +0200 Subject: [PATCH] Add first version of release CI --- .github/workflows/release.yml | 118 ++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..f927374 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,118 @@ +name: Release + +on: + push: + tags: + - "v*" + +jobs: + create_release: + name: Create Github Release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Create Release + id: create_release + uses: actions/create-release@v1.1.4 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: true + prerelease: false + + - name: Output Release URL File + run: echo "${{ steps.create_release.outputs.upload_url }}" > release_url.txt + - name: Save Release URL File for publish + uses: actions/upload-artifact@v3 + with: + name: release_url + path: release_url.txt + + build_artifact: + needs: [create_release] + name: ${{ matrix.os }}/GHC ${{ matrix.ghc }}/${{ github.ref }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macOS-latest, windows-latest] + ghc: + - "9.6.5" + stack: ["2.15.7"] + + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Set tag name + uses: olegtarasov/get-tag@v2.1.2 + id: tag + with: + tagRegex: "v(.*)" + tagRegexGroup: 1 + + - name: Setup Haskell + uses: haskell/actions/setup@v2.7.3 + id: setup-haskell-cabal + with: + ghc-version: ${{ matrix.ghc }} + enable-stack: true + stack-version: ${{ matrix.cabal }} + + + - name: Cache ~/.stack + uses: actions/cache@v4 + with: + path: ~/.stack + key: ${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('**/stack.yaml.lock','**/gitlab-helper.cabal') }}-v2 + restore-keys: | + ${{ runner.os }}-${{ matrix.ghc }}- + + - name: Build binary + run: | + mkdir bin + stack build --pedantic --copy-bins --local-bin-path bin + + - if: matrix.os == 'windows-latest' + name: Set binary path name on Windows + run: echo "BINARY_PATH=./bin/gitlab-helper.exe" >> $env:GITHUB_ENV + + - if: matrix.os != 'windows-latest' + name: Set binary path name not on Windows + run: echo "BINARY_PATH=./bin/gitlab-helper-exe" >> "$GITHUB_ENV" + + - name: Compress binary + uses: svenstaro/upx-action@2.3.0 + with: + file: ${{ env.BINARY_PATH }} + + - name: Load Release URL File from release job + uses: actions/download-artifact@v3 + with: + name: release_url + path: release_url + + - if: matrix.os == 'windows-latest' + name: Get Release File Name & Upload URL on Widows + run: | + echo "upload_url=$(cat release_url/release_url.txt)" >> $env:GITHUB_ENV + + # See Note [environment variables] + - if: matrix.os != 'windows-latest' + name: Get Release File Name & Upload URL not on Widows + run: | + echo "upload_url=$(cat release_url/release_url.txt)" >> $GITHUB_ENV + + - name: Upload Release Asset + id: upload-release-asset + uses: actions/upload-release-asset@v1.0.2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ env.upload_url }} + asset_path: ${{ env.BINARY_PATH }} + asset_name: gitlab-helper-${{ steps.tag.outputs.tag }}-${{ runner.os }}-ghc-${{ matrix.ghc }}${{ env.EXT }} + asset_content_type: application/octet-stream \ No newline at end of file