stuff #2
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
name: Binaries | |
defaults: | |
run: | |
shell: bash | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
jobs: | |
build: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
ghc: ["9.6.6", "9.4.8"] | |
os: [ubuntu-latest, windows-latest] | |
include: | |
- ghc: "9.6.6" | |
os: macOS-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: haskell-actions/setup@v2 | |
id: setup-haskell | |
with: | |
ghc-version: ${{ matrix.ghc }} | |
cabal-version: 3.12.1.0 | |
- name: Set some window specific things | |
if: matrix.os == 'windows-latest' | |
run: echo 'EXE_EXT=.exe' >> $GITHUB_ENV | |
- name: Cabal update | |
run: cabal update | |
- name: Configure project | |
run: | | |
cabal configure --enable-tests --enable-benchmarks --write-ghc-environment-files=ghc8.4.4+ | |
cabal build all --dry-run | |
- name: Cabal cache over S3 | |
uses: action-works/cabal-cache-s3@v1 | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
BINARY_CACHE_URI: ${{ vars.BINARY_CACHE_URI }} | |
with: | |
region: us-west-2 | |
dist-dir: dist-newstyle | |
store-path: ${{ steps.setup-haskell.outputs.cabal-store }} | |
threads: 16 | |
archive-uri: ${{ env.BINARY_CACHE_URI }} | |
skip: "${{ env.BINARY_CACHE_URI == '' }}" | |
- name: Cabal cache over HTTPS | |
uses: action-works/cabal-cache-s3@v1 | |
with: | |
dist-dir: dist-newstyle | |
store-path: ${{ steps.setup-haskell.outputs.cabal-store }} | |
threads: 16 | |
archive-uri: https://cache.haskellworks.io/archive | |
- name: Build | |
run: | | |
cabal build all --enable-tests --enable-benchmarks | |
- name: Test | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
run: | | |
cabal test all --enable-tests --enable-benchmarks --write-ghc-environment-files=ghc8.4.4+ | |
- name: Compress Binary | |
id: compress_binary | |
env: | |
GHC_VER: ${{ matrix.ghc }} | |
run: | | |
HS_BIN=$(find dist-newstyle \( -name 'cabal-cache' -o -name 'cabal-cache.exe' \) -type f | head -n 1) | |
test -f "$HS_BIN" | |
NAME="cabal-cache" | |
case ${{ matrix.os }} in | |
ubuntu-*) os="linux" ;; | |
macOS-*) os="darwin" ;; | |
windows-*) os="windows" ;; | |
*) exit 1 ;; # error | |
esac | |
arch_os="$(uname -m)-$os" | |
cp "$HS_BIN" "$NAME${{env.EXE_EXT}}" | |
[ "$OS" != Windows_NT ] && strip "$NAME${{env.EXE_EXT}}" | |
mkdir -p artifacts | |
7z a "artifacts/$NAME-$arch_os.zip" "$NAME${{env.EXE_EXT}}" | |
echo "path_zip=$NAME.zip" >> $GITHUB_OUTPUT | |
gzip -c --best "$NAME${{env.EXE_EXT}}" > artifacts/$NAME-$arch_os${{env.EXE_EXT}}.gz | |
echo "path_gzip=$NAME.gz" >> $GITHUB_OUTPUT | |
tar zcvf "artifacts/$NAME-$arch_os.tar.gz" "$NAME${{env.EXE_EXT}}" | |
echo "path_targz=$NAME.targz" >> $GITHUB_OUTPUT | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: cabal-cache-${{ runner.OS }}-${{ matrix.ghc }} | |
path: artifacts | |
check: | |
needs: build | |
runs-on: ubuntu-latest | |
outputs: | |
tag: ${{ steps.tag.outputs.tag }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Check if cabal project is sane | |
run: | | |
PROJECT_DIR=$PWD | |
mkdir -p $PROJECT_DIR/build/sdist | |
for i in $(git ls-files | grep '\.cabal'); do | |
cd $PROJECT_DIR && cd `dirname $i` | |
cabal check | |
done | |
- name: Tag new version | |
id: tag | |
if: ${{ github.ref == 'refs/heads/main' }} | |
env: | |
server: http://hackage.haskell.org | |
username: ${{ secrets.HACKAGE_USER }} | |
password: ${{ secrets.HACKAGE_PASS }} | |
run: | | |
package_version="$(cat *.cabal | grep '^version:' | cut -d : -f 2 | xargs)" | |
echo "Package version is v$package_version" | |
git fetch --unshallow origin | |
if git tag "v$package_version"; then | |
echo "Tagging with new version "v$package_version"" | |
if git push origin "v$package_version"; then | |
echo "Tagged with new version "v$package_version"" | |
echo "tag=v$package_version" >> $GITHUB_OUTPUT | |
fi | |
fi | |
release: | |
needs: [build, check] | |
runs-on: ubuntu-latest | |
if: ${{ needs.check.outputs.tag != '' }} | |
outputs: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Create source distribution | |
run: | | |
PROJECT_DIR=$PWD | |
mkdir -p $PROJECT_DIR/build/sdist | |
for i in $(git ls-files | grep '\.cabal'); do | |
cd $PROJECT_DIR && cd `dirname $i` | |
cabal v2-sdist -o $PROJECT_DIR/build/sdist | |
done; | |
- name: Publish to hackage | |
env: | |
server: http://hackage.haskell.org | |
username: ${{ secrets.HACKAGE_USER }} | |
password: ${{ secrets.HACKAGE_PASS }} | |
candidate: true | |
run: | | |
package_version="$(cat *.cabal | grep '^version:' | cut -d : -f 2 | xargs)" | |
for PACKAGE_TARBALL in $(find ./build/sdist/ -name "*.tar.gz"); do | |
PACKAGE_NAME=$(basename ${PACKAGE_TARBALL%.*.*}) | |
if ${{ env.candidate }}; then | |
TARGET_URL="${{ env.server }}/packages/candidates"; | |
DOCS_URL="${{ env.server }}/package/$PACKAGE_NAME/candidate/docs" | |
else | |
TARGET_URL="${{ env.server }}/packages/upload"; | |
DOCS_URL="${{ env.server }}/package/$PACKAGE_NAME/docs" | |
fi | |
HACKAGE_STATUS=$(curl --silent --head -w %{http_code} -XGET --anyauth --user "${{ env.username }}:${{ env.password }}" ${{ env.server }}/package/$PACKAGE_NAME -o /dev/null) | |
if [ "$HACKAGE_STATUS" = "404" ]; then | |
echo "Uploading $PACKAGE_NAME to $TARGET_URL" | |
curl -X POST -f --user "${{ env.username }}:${{ env.password }}" $TARGET_URL -F "package=@$PACKAGE_TARBALL" | |
echo "Uploaded $PACKAGE_NAME" | |
else | |
echo "Package $PACKAGE_NAME" already exists on Hackage. | |
fi | |
done | |
- name: Create Release | |
id: create_release | |
uses: softprops/action-gh-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token | |
with: | |
tag_name: ${{ needs.check.outputs.tag }} | |
release_name: Release ${{ needs.check.outputs.tag }} | |
body: Undocumented | |
draft: true | |
prerelease: false | |
publish: | |
needs: [build, release] | |
runs-on: ${{ matrix.os }} | |
if: ${{ needs.check.outputs.tag != '' }} | |
strategy: | |
fail-fast: false | |
matrix: | |
ghc: ["9.6.6"] | |
os: [ubuntu-latest, macOS-latest, windows-latest] | |
steps: | |
- uses: actions/download-artifact@v4 | |
id: download_artifact | |
with: | |
name: cabal-cache-${{ runner.OS }}-${{ matrix.ghc }} | |
path: artifacts | |
- name: URL | |
run: ls artifacts | |
- name: Compute axes | |
id: axes | |
run: | | |
case ${{ matrix.os }} in | |
ubuntu-*) os="linux" ;; | |
macOS-*) os="darwin" ;; | |
windows-*) os="windows" ;; | |
*) exit 1 ;; # error | |
esac | |
arch_os="$(uname -m)-$os" | |
echo "arch_os=$arch_os" >> $GITHUB_OUTPUT | |
- name: Set some window specific things | |
if: matrix.os == 'windows-latest' | |
run: echo 'EXE_EXT=.exe' >> $GITHUB_ENV | |
- name: Upload Release Binary | |
uses: actions/[email protected] | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ needs.release.outputs.upload_url }} | |
asset_path: artifacts/cabal-cache-${{ steps.axes.outputs.arch_os }}${{env.EXE_EXT}}.gz | |
asset_name: cabal-cache-${{ steps.axes.outputs.arch_os }}.gz | |
asset_content_type: application/gzip | |
- name: Upload Release Binary | |
uses: actions/[email protected] | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ needs.release.outputs.upload_url }} | |
asset_path: artifacts/cabal-cache-${{ steps.axes.outputs.arch_os }}.tar.gz | |
asset_name: cabal-cache-${{ steps.axes.outputs.arch_os }}.tar.gz | |
asset_content_type: application/gzip | |
- name: Upload Release Binary | |
uses: actions/[email protected] | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ needs.release.outputs.upload_url }} | |
asset_path: artifacts/cabal-cache-${{ steps.axes.outputs.arch_os }}.zip | |
asset_name: cabal-cache-${{ steps.axes.outputs.arch_os }}.zip | |
asset_content_type: application/zip |