Skip to content

Commit

Permalink
Initial release (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-martin authored Jan 8, 2025
1 parent 80c76c9 commit 539ed24
Show file tree
Hide file tree
Showing 17 changed files with 1,134 additions and 427 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
62 changes: 62 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Release

on:
push:
branches: main
workflow_dispatch:

jobs:
tag:
runs-on: ubuntu-latest
env:
SHA: ${{ github.sha }}
GH_TOKEN: ${{ github.token }}

steps:
- uses: actions/checkout@v4

- id: tag
name: Tag
run: |
TAG=$(<version.txt)
if gh api "/repos/{owner}/{repo}/git/ref/tags/$TAG" &>/dev/null; then
echo "Tag $TAG exists already"
exit 0
fi
gh api '/repos/{owner}/{repo}/git/tags' \
--method POST \
--raw-field "tag=$TAG" \
--raw-field "message=$TAG" \
--raw-field "object=$SHA" \
--raw-field "type=commit"
gh api '/repos/{owner}/{repo}/git/refs' \
--method POST \
--raw-field "ref=refs/tags/$TAG" \
--raw-field "sha=$SHA"
echo "tag=$TAG" >>"$GITHUB_OUTPUT"
release:
needs: tag
if: needs.tag.outputs.tag
runs-on: ubuntu-latest
env:
HACKAGE_KEY: ${{ secrets.HACKAGE_UPLOAD_API_KEY }}

steps:
- uses: actions/checkout@v4

- name: "Build with Haddocks"
uses: freckle/stack-action@v5
with:
test: false
stack-build-arguments: --haddock --haddock-for-hackage

- name: "Release to Hackage"
run: stack --stack-yaml stack-lts20.yaml upload --pvp-bounds lower recurly-client

- name: "Upload documentation"
run: stack upload --documentation recurly-client
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.stack-work
*.hie
.hiedb
stack-*.lock
stack.*.lock
.direnv
44 changes: 31 additions & 13 deletions Justfile
Original file line number Diff line number Diff line change
@@ -1,39 +1,57 @@
set shell := ["bash", "-uc"]

# Delete all generated code and re-regenerate it all anew
regenerate: clean fetch convert-to-json generate-haskell-code fix-nulls format-generated-code set-package-version
regenerate: clean fetch convert-to-json generate-haskell-code fix-nulls format-generated-code patch-cabal-file

# Delete all generated code
clean:
#!/usr/bin/env bash
rm -rf spec.json spec.yaml recurly-client
rm -rf spec.json spec.yaml recurly-client/src recurly-client/*.cabal

# Download the OpenAPI spec
fetch:
#!/usr/bin/env bash
curl --fail https://recurly.com/developers/api/spec/v2021-02-25.yaml -o spec.yaml

# Convert the downloaded OpenAPI spec to JSON
convert-to-json:
#!/usr/bin/env -S nix shell nixpkgs#yq --command bash
yq '.' spec.yaml > spec.json

# Use openapi3-code-generator to generate Haskell code
generate-haskell-code:
#!/usr/bin/env -S nix shell --accept-flake-config 'github:freckle/flakes?dir=main#haskell-openapi3-code-generator-default' --command bash
openapi3-code-generator-exe --configuration generator-config.yaml

# Replace .:! with .:? to change Null to Nothing
fix-nulls:
#!/usr/bin/env -S nix shell nixpkgs#perl --command bash
find recurly-client/src -type f -iname "*.hs" -exec \
perl -p -i -e 's/Data\.Aeson\.Types\.FromJSON\.\.:!/Data.Aeson.Types.FromJSON..:?/g' {} \;

# Run fourmolu on the generated Haskell code
format-generated-code:
#!/usr/bin/env -S nix shell --accept-flake-config 'github:freckle/flakes?dir=main#fourmolu-default' --command bash
fourmolu -i recurly-client/src --unsafe

# Use version.txt as the version in the .cabal file
set-package-version:
#!/usr/bin/env bash
VERSION=$(cat version.txt)
perl -p -i -e "s/^(version: *).*$/\${1}${VERSION}/" recurly-client/recurly-client.cabal
patch-cabal-file:
grep -v "^version:" recurly-client/recurly-client.cabal \
> recurly-client/recurly-client.cabal.tmp.1

# First line contains cabal-version
head -n1 recurly-client/recurly-client.cabal.tmp.1 \
> recurly-client/recurly-client.cabal.tmp.2

# Set version
echo -n "version: " >> recurly-client/recurly-client.cabal.tmp.2
cat ./version.txt >> recurly-client/recurly-client.cabal.tmp.2

# Add extra top-level fields
cat ./cabal-fields.txt >> recurly-client/recurly-client.cabal.tmp.2

# Copy the rest
tail -n +2 recurly-client/recurly-client.cabal.tmp.1 \
>> recurly-client/recurly-client.cabal.tmp.2

# Replace the original
mv -f recurly-client/recurly-client.cabal.tmp.2 recurly-client/recurly-client.cabal

# Clean up temporarily files
rm recurly-client/recurly-client.cabal.tmp.*

# Clean up cabal file
cabal-fmt -i recurly-client/recurly-client.cabal
4 changes: 4 additions & 0 deletions cabal-fields.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
category: Client, Payments
homepage: https://github.com/freckle/recurly-client
license-file: LICENSE
license: MIT
Loading

0 comments on commit 539ed24

Please sign in to comment.