diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..f541801 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,25 @@ +name: CI + +on: + pull_request: + push: + branches: [master] + +jobs: + test: + runs-on: ubuntu-latest + + strategy: + matrix: + stack-yaml: + - stack.yaml + fail-fast: false + + steps: + - uses: actions/checkout@v2 + - uses: freckle/stack-cache-action@main + with: + stack-yaml: ${{ matrix.stack-yaml }} + - uses: freckle/stack-action@main + with: + stack-yaml: ${{ matrix.stack-yaml }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..b0c2d8b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,114 @@ +name: Release + +on: + push: + tags: + - 'v*' + +jobs: + create_release: + name: Create Github Release + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Create Release + id: create_release + uses: actions/create-release@v1.1.1 + 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@v1 + 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: + matrix: + os: [ubuntu-latest, macOS-latest, windows-latest] + ghc: ["8.10.4"] + cabal: ["3.4"] + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set tag name + uses: olegtarasov/get-tag@v2.1 + id: tag + with: + tagRegex: "v(.*)" + tagRegexGroup: 1 + + - name: Setup Haskell + uses: haskell/actions/setup@v1 + id: setup-haskell-cabal + with: + ghc-version: ${{ matrix.ghc }} + cabal-version: ${{ matrix.cabal }} + + - name: Freeze + run: | + cabal freeze + + - name: Cache ~/.cabal/store + uses: actions/cache@v1 + with: + path: ${{ steps.setup-haskell-cabal.outputs.cabal-store }} + key: ${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('cabal.project.freeze') }} + + - name: Build binary + run: | + mkdir dist + cabal install exe:roadburn-redux-crawler --install-method=copy --overwrite-policy=always --installdir=dist + + - if: matrix.os != 'windows-latest' + name: Set binary path name (non-Windows) + run: | + echo "BINARY_PATH=./dist/roadburn-redux-crawler${{ env.EXT }}" >> $GITHUB_ENV + + - if: matrix.os == 'windows-latest' + name: Set binary path name and extension (Windows) + run: | + echo "EXT=.exe" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + echo "BINARY_PATH=./dist/roadburn-redux-crawler.exe" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + + - name: Compress binary + uses: svenstaro/upx-action@2.0.1 + with: + file: ${{ env.BINARY_PATH }} + + - name: Load Release URL File from Release Job + uses: actions/download-artifact@v1 + with: + name: release_url + + - name: Get Release File Name and Upload URL + id: get_release_info + run: | + echo "::set-output name=upload_url::$(cat release_url/release_url.txt)" + + - name: Upload Release Asset + id: upload-release-asset + uses: actions/upload-release-asset@v1.0.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.get_release_info.outputs.upload_url }} + asset_path: ${{ env.BINARY_PATH }} + asset_name: roadburn-redux-crawler-${{ steps.tag.outputs.tag }}-${{ runner.os }}-ghc-${{ matrix.ghc }}${{ env.EXT }} + asset_content_type: application/octet-stream