Skip to content

Commit f526de0

Browse files
authored
Merge pull request #7 from geniusyield/5-ci-for-dex-contracts-api
CI for dex-contracts-api #5
2 parents cf360d6 + 7de7a51 commit f526de0

File tree

5 files changed

+244
-0
lines changed

5 files changed

+244
-0
lines changed

.github/workflows/build.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Validate
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
permissions:
10+
contents: read
11+
pages: write
12+
id-token: write
13+
14+
concurrency:
15+
group: "pages"
16+
cancel-in-progress: false
17+
18+
jobs:
19+
validate:
20+
uses: ./.github/workflows/haskell.yml
21+
secrets: inherit
22+
23+
deploy-haddock:
24+
runs-on: ubuntu-latest
25+
needs: validate
26+
if: github.ref == 'refs/heads/main'
27+
environment:
28+
name: github-pages
29+
url: ${{ steps.deployment.outputs.page_url }}
30+
steps:
31+
- name: Deploy to GitHub Pages
32+
id: deployment
33+
uses: actions/deploy-pages@v2

.github/workflows/haskell.yml

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
name: Haskell CI
2+
3+
on:
4+
workflow_call:
5+
outputs:
6+
VERSION:
7+
description: "VERSION"
8+
value: ${{ jobs.build.outputs.VERSION }}
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-22.04
16+
outputs:
17+
VERSION: ${{ steps.get_version.outputs.VERSION }}
18+
steps:
19+
- name: Checkout source code
20+
uses: actions/checkout@v3
21+
- name: Install dependencies (apt-get)
22+
run: |
23+
sudo apt-get update
24+
sudo apt-get install -y --no-install-recommends \
25+
autoconf \
26+
automake \
27+
build-essential \
28+
ca-certificates \
29+
chrony \
30+
dpkg-dev \
31+
gcc \
32+
gnupg \
33+
g++ \
34+
hlint \
35+
libc6-dev \
36+
libncursesw5 \
37+
libffi-dev \
38+
libgmp-dev \
39+
liblzma-dev \
40+
libnuma-dev \
41+
libpq-dev \
42+
libssl-dev \
43+
libsystemd-dev \
44+
libtinfo-dev \
45+
libtool \
46+
netbase \
47+
pkg-config \
48+
procps \
49+
tmux \
50+
xz-utils \
51+
zlib1g-dev
52+
- name: Validate code (run pre-commit hooks)
53+
uses: pre-commit/[email protected]
54+
with:
55+
extra_args: --verbose --all-files
56+
- name: Setup haskell tooling
57+
uses: haskell/actions/setup@v2
58+
with:
59+
ghc-version: '9.2.8'
60+
cabal-version: '3.10.1.0'
61+
enable-stack: true
62+
stack-version: '2.9'
63+
- name: Setup cache
64+
uses: actions/cache@v3
65+
env:
66+
cache-name: cache-cabal
67+
with:
68+
path: ~/.cabal
69+
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/*.cabal') }}-${{ hashFiles('**/cabal.project') }}
70+
restore-keys: |
71+
${{ runner.os }}-build-${{ env.cache-name }}-
72+
${{ runner.os }}-build-
73+
${{ runner.os }}-
74+
- name: Install LIBSODIUM
75+
run: |
76+
git clone https://github.com/input-output-hk/libsodium
77+
cd libsodium
78+
git checkout dbb48cc
79+
./autogen.sh
80+
./configure
81+
make
82+
sudo make install
83+
sudo ldconfig
84+
- name: Install SEPC256K1
85+
run: |
86+
git clone https://github.com/bitcoin-core/secp256k1
87+
cd secp256k1
88+
git checkout ac83be33d0956faf6b7f61a60ab524ef7d6a473a
89+
./autogen.sh
90+
./configure --prefix=/usr --enable-module-schnorrsig --enable-experimental
91+
make
92+
sudo make install
93+
sudo ldconfig
94+
- name: Update dependencies (cabal)
95+
run: cabal update
96+
# TODO: [CI] Add fourmolu #10
97+
#- name: Install fourmolu
98+
# run: cabal install fourmolu
99+
#- name: Run checks (fourmolu)
100+
# run: fourmolu --mode check src
101+
- name: Build dependencies (cabal)
102+
run: cabal build --only-dependencies --enable-tests --enable-benchmarks
103+
- name: Build all targets (cabal)
104+
run: cabal build --enable-tests --enable-benchmarks all
105+
# TODO: [CI] Add cabal check #9
106+
#- name: Run checks (cabal)
107+
# run: cabal check
108+
# TODO: [CI] Create source distribution file #11
109+
#- name: Create source distribution file (cabal)
110+
# run: cabal sdist
111+
- name: Identify version (cabal)
112+
id: get_version
113+
run: |
114+
export VERSION=$(cabal info . | awk '{print $2 ;exit}') ;
115+
echo "VERSION: $VERSION"
116+
echo "VERSION=${VERSION}" >> $GITHUB_ENV
117+
echo "VERSION=${VERSION}" >> $GITHUB_OUTPUT
118+
- name: Generate documentation (cabal haddock)
119+
run: cabal haddock --html --hyperlink-source --haddock-options="--use-unicode" --haddock-quickjump
120+
- name: Upload haddock documentation
121+
uses: actions/[email protected]
122+
with:
123+
path: ./dist-newstyle/build/x86_64-linux/ghc-9.2.8/${{env.VERSION}}/doc/html/geniusyield-dex-api/
124+
# TODO: [CI] Create source distribution file #11
125+
#- name: Upload artifacts
126+
# uses: actions/upload-artifact@v3
127+
# with:
128+
# name: source-distribution-file
129+
# path: ./dist-newstyle/sdist/${{env.VERSION}}.tar.gz

.github/workflows/release.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- "v*"
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
build:
13+
uses: ./.github/workflows/haskell.yml
14+
secrets: inherit
15+
release:
16+
runs-on: ubuntu-22.04
17+
needs: build
18+
steps:
19+
- name: Checkout source code
20+
uses: actions/checkout@v3
21+
- uses: actions/download-artifact@v3
22+
name: Download source distribution file artifact
23+
with:
24+
name: source-distribution-file
25+
path: ./artifacts
26+
- uses: actions/download-artifact@v3
27+
name: Download haddock artifact
28+
with:
29+
name: github-pages
30+
path: ./artifacts
31+
- name: Create release draft (GitHub)
32+
env:
33+
VERSION: ${{needs.build.outputs.VERSION}}
34+
run: |
35+
export GH_TOKEN=${{ secrets.GITHUB_TOKEN }}
36+
SEMANTIC_VERSION=v${VERSION/#geniusyield-dex-api-}
37+
TAGS=$(git describe --tags)
38+
GIT_REVISION=$(git rev-parse HEAD)
39+
CI_BUILD_TIME=$(date --iso-8601=seconds --utc)
40+
echo "VERSION: ${{ env.VERSION }}"
41+
echo "SEMANTIC_VERSION: $SEMANTIC_VERSION"
42+
echo "TAGS: $TAGS"
43+
echo "GIT_REVISION: $GIT_REVISION"
44+
echo "CI_BUILD_TIME: $CI_BUILD_TIME"
45+
HADDOCK_FILE=${{ env.VERSION }}-haddock.tar
46+
set -x
47+
mv ./artifacts/artifact.tar ./artifacts/${HADDOCK_FILE}
48+
gh release create \
49+
--generate-notes \
50+
--verify-tag \
51+
--draft \
52+
"${SEMANTIC_VERSION}" \
53+
"./artifacts/${HADDOCK_FILE}#Haddock (tar)"
54+
echo "::notice::Succesfully created release draft ${SEMANTIC_VERSION} from ${GIT_REVISION}. (Uploaded: ${{ env.VERSION }}.tar.gz)"

.pre-commit-config.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.4.0
4+
hooks:
5+
- id: check-yaml
6+
- repo: local
7+
hooks:
8+
- id: no-commit-to-main
9+
name: no-commit-to-main
10+
description: Reject commits to main branch (but not on CI)
11+
entry: bash ./no-commit-to-main.sh
12+
always_run: true
13+
language: system
14+
- repo: https://github.com/geniusyield/atlas
15+
rev: 467bb60894cc381ec7aa3eba118aebf58325ffd3
16+
hooks:
17+
- id: hlint-ignore-duplication

no-commit-to-main.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
if [ "${CI:=false}" == "true" ]; then
3+
echo "Running on CI. Nothing to check."
4+
exit 0;
5+
fi
6+
7+
BRANCH=$(git branch --show-current)
8+
if [ "$BRANCH" == "main" ]; then
9+
echo "No commits allowed on $BRANCH branch!"
10+
exit 1;
11+
fi

0 commit comments

Comments
 (0)