run ci every push #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# documentation | |
# https://github.com/haskell/actions | |
# https://kodimensional.dev/github-actions | |
# uses | |
# - actions/checkout (3) | |
# https://github.com/marketplace/actions/checkout | |
# - actions/cache (3) | |
# https://github.com/marketplace/actions/cache | |
# - haskell/actions/setup (2) | |
# https://github.com/haskell/actions | |
# - softprops/action-gh-release (1) [seems no longer maintained] | |
# https://github.com/softprops/action-gh-release | |
# - ncipollo/release-action (1) [possible replacement] | |
# https://github.com/ncipollo/release-action | |
# TODO: check and add caching if needed | |
# TODO: automatize setting program & version | |
# TODO: option to release snapshot versions | |
# TODO: make one workflow for each OS ? | |
# Requirements: | |
# - tags activating releases should begin with v (eg: v1.0.0) [checked] | |
# - tags should only be done on "master" commits [not checked] | |
# Notes: | |
# - zip is removed for linux and macOS, if needed this can be added: zip -j ${{ env.archive }}.zip ${{ env.bin_path }}/${{ env.program }} | |
# - startsWith(github.ref, 'refs/tags/v') is not working with on:push:branches:[master] | |
# so we use on:push:tags: but then it is not checked if the branch is master/main | |
name: CI | |
on: | |
push: | |
branches: | |
- '*' | |
env: | |
lts: 20.5 | |
program: template-haskell-project-exe | |
version: 0.1.4.0 | |
jobs: | |
build: | |
name: build-${{ matrix.ghc }}-${{ matrix.stack }}-${{ matrix.os }} | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
ghc: ['9.2.5'] | |
stack: ['2.9.1'] | |
os: [ubuntu-latest, macOS-latest, windows-latest] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: stack setup | |
uses: haskell/actions/setup@v2 | |
with: | |
ghc-version: ${{ matrix.ghc }} | |
enable-stack: true | |
stack-version: ${{ matrix.stack }} | |
# | |
# caches | |
# | |
- name: cache ~/.stack (linux and macOS) | |
uses: actions/cache@v3 | |
if: startsWith(matrix.os, 'windows') != true | |
with: | |
path: ~/.stack | |
key: stack-${{ matrix.ghc }}-${{ matrix.stack }}-${{ env.lts }}-${{ runner.os }} | |
- name: cache C:\sr\snapshots (windows x86) | |
uses: actions/cache@v3 | |
if: startsWith(matrix.os, 'windows') | |
with: | |
path: C:\sr\snapshots | |
key: stack-${{ matrix.ghc }}-${{ matrix.stack }}-${{ env.lts }}-${{ runner.os }} | |
# | |
# building & testing | |
# | |
- name: install dependencies | |
run: | | |
stack build --system-ghc --test --bench --no-run-tests --no-run-benchmarks --only-dependencies | |
- name: build | |
run: | | |
stack build --system-ghc --test --bench --no-run-tests --no-run-benchmarks | |
- name: test | |
run: | | |
stack test --system-ghc | |
# | |
# setting os, arch, and bin_path | |
# | |
- name: set variables (linux x86) | |
if: startsWith(matrix.os, 'ubuntu') | |
run: | | |
echo os=linux >> $GITHUB_ENV | |
echo arch="x86_64" >> $GITHUB_ENV | |
echo bin_path=`stack path --system-ghc --local-install-root`/bin >> $GITHUB_ENV | |
- name: set variables (mac x86) | |
if: startsWith(matrix.os, 'macOS') | |
run: | | |
echo os=osx >> $GITHUB_ENV | |
echo arch="x86_64" >> $GITHUB_ENV | |
echo bin_path=`stack path --system-ghc --local-install-root`/bin >> $GITHUB_ENV | |
- name: set variables (windows) | |
if: startsWith(matrix.os, 'windows') | |
run: | | |
echo "os=windows" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append | |
echo "arch=x86_64" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append | |
$pwsh_bin_path = Join-Path (& stack path --system-ghc --local-install-root) bin | |
echo "bin_path=$pwsh_bin_path" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append | |
shell: pwsh | |
# | |
# setting archive name | |
# | |
- name: set archive name (linux and macOS) | |
if: startsWith(matrix.os, 'windows') != true | |
run: | | |
echo "archive=${{ env.program }}-${{ env.version }}-${{ env.os }}.${{ env.arch }}" >> $GITHUB_ENV | |
- name: set archive name (windows) | |
if: startsWith(matrix.os, 'windows') | |
run: | | |
$pwsh_archive = $Env:program+"-"+$Env:version+"-"+$Env:os+"."+$Env:arch | |
echo "archive=$pwsh_archive" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append | |
shell: pwsh | |
# | |
# make archives | |
# | |
- name: make archive (linux and macOS) | |
if: startsWith(matrix.os, 'windows') != true | |
run: | | |
tar czf ${{ env.archive }}.tar.gz -C ${{ env.bin_path }} ${{ env.program }} | |
echo archive ${{ env.archive }}.tar.gz created from ${{ env.bin_path }}/${{ env.program }} | |
echo "archive_path=${{ env.archive }}.tar.gz" >> $GITHUB_ENV | |
echo "archive_type=application/tar+gzip" >> $GITHUB_ENV | |
- name: make archive (windows) | |
if: startsWith(matrix.os, 'windows') | |
run: | | |
$file = Join-Path $Env:bin_path ($Env:program+".exe") | |
$pwsh_archive_path = ($Env:archive+".zip") | |
Get-ChildItem $file | Compress-Archive -DestinationPath $pwsh_archive_path | |
echo archive ($Env:archive+".zip") created from $file | |
echo "archive_path=$pwsh_archive_path" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append | |
echo "archive_type=application/zip" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append | |
# | |
# release | |
# | |
# OLD VERSION NOT WORKING | |
# - name: release | |
# uses: softprops/action-gh-release@v1 | |
# with: | |
# # tag_name: defaults to github.ref | |
# # name: defaults to tag name | |
# # token: default to ${{ secrets.GITHUB_TOKEN }} | |
# append_body: true | |
# files: | | |
# ${{ env.archive_path }} | |
# NEW VERSION | |
- name: information | |
run: | | |
echo ${{ env.archive_path }} | |
echo ${{ env.archive_type }} | |
pwd | |
ls -al | |
shell: bash | |
- name: release | |
uses: ncipollo/release-action@v1.12.0 | |
with: | |
allowUpdates: true | |
artifactErrorsFailBuild: true | |
artifacts: ${{ env.archive_path }} | |
artifactContentType: $${{ env.archive_type }} |