Skip to content

Commit

Permalink
automatically upload binaries for: linux, mac-os, windows (#780)
Browse files Browse the repository at this point in the history
* fix:

* nix

* update

* nix

* binary.sh

* ls

* update publish binary

* setup-hs

* update binaries

* generate stack config

* setup

* remove sh

* releases

* binaries

* upload

* Token

* binary

* update zip

* windows latest

* exe

* execName

* out

* update

* update

* cd out

* with bash

* update

* shell

* -l

* test os

* update

* update tests

* artifacts

* upload

* checkout

* update on push

* binaries

* dynamic url generation

* generate cabal files
  • Loading branch information
nalchevanidze authored Oct 24, 2022
1 parent 611561d commit c37d623
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 74 deletions.
14 changes: 0 additions & 14 deletions .github/actions/sdist/action.yaml

This file was deleted.

32 changes: 32 additions & 0 deletions .github/actions/setup-hs/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Source Distribution
inputs:
ghc:
description: GHC Version
required: false
default: latest

runs:
using: "composite"
steps:
- name: Setup Node
uses: actions/setup-node@v3

- name: generate stack config
run: |
npm i
npm run setup ${{ inputs.ghc }}
shell: bash

- name: Setup Haskell
uses: haskell/actions/[email protected]
with:
ghc-version: ${{ inputs.ghc }}
enable-stack: true

- name: Cache Stack
uses: actions/cache@v2
with:
path: ~/.stack
key: ${{ runner.os }}-${{ inputs.ghc }}-stack-${{ hashFiles('stack.yaml') }}
restore-keys: |
${{ runner.os }}-${{ inputs.ghc }}-stack
13 changes: 6 additions & 7 deletions .github/workflows/draft-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@ jobs:
- run: git fetch --prune --unshallow

- name: Setup
uses: actions/setup-node@v1
uses: ./.github/actions/setup-hs
with:
node-version: 14.x

- name: Install
run: npm i
ghc: latest

- name: Draft Release
id: draft
run: npm run release -- draft
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Source Distribution
uses: ./.github/actions/sdist
- name: Generate Cabal Files
run: |
stack build --test --dry-run
stack sdist
- name: Open Release Pull Request
run: |
Expand Down
26 changes: 3 additions & 23 deletions .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ jobs:
build:
strategy:
matrix:
# "8.2.2" TODO: fix: ByteCodeLink.lookupCE
ghc: ["8.4.4", "8.6.5", "8.8.3", "8.10.7", "9.0.2", "latest"]
os: [ubuntu-latest]
fail-fast: true
Expand All @@ -15,29 +14,10 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Setup Node
uses: actions/setup-node@v3

- name: Install Node
run: npm i

- name: setup stack config
run: npm run setup ${{ matrix.ghc }}

- name: Setup Haskell
uses: haskell/actions/[email protected]
- name: Setup
uses: ./.github/actions/setup-hs
with:
ghc-version: ${{ matrix.ghc }}
enable-stack: true
- name: Cache Stack
uses: actions/cache@v2
with:
path: ~/.stack
key: ${{ runner.os }}-${{ matrix.ghc }}-stack-${{ hashFiles('stack.yaml') }}
restore-keys: |
${{ runner.os }}-${{ matrix.ghc }}-stack
# Install & Build & Test
ghc: ${{ matrix.ghc }}

- name: Install dependencies
run: stack build --fast --skip-ghc-check --no-terminal --test --only-dependencies
Expand Down
80 changes: 80 additions & 0 deletions .github/workflows/upload-artifacts.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Upload Artifacts
on:
release:
types: [published]

# thanks to: https://github.com/tweag/ormolu/blob/master/.github/workflows/binaries.yml

jobs:
build:
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: linux
executable: morpheus
- os: macOS-latest
target: mac-os
executable: morpheus
- os: windows-latest
target: windows
executable: morpheus.exe
name: Upload Artifacts for ${{ matrix.target }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2

- name: setup
uses: ./.github/actions/setup-hs
with:
ghc: latest

- name: Build Artifacts
run: stack build morpheus-graphql-code-gen
shell: bash

- name: Prepare Artifacts
run: |
mkdir out
cd ./out
cp $(stack exec which morpheus) ./${{ matrix.executable }}
7z a ../morpheus.zip .
shell: bash

- name: Upload Artifact
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: morpheus.zip
asset_name: morpheus-${{ matrix.target }}.zip
asset_content_type: application/octet-stream
test:
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target: linux
- os: macOS-latest
target: mac-os
- os: windows-latest
target: windows
name: Test Binaries
runs-on: ${{ matrix.os }}
needs: build
steps:
- uses: actions/checkout@v2
- name: Download and extract Artifact
run: |
curl -o morpheus.zip -LO https://github.com/${{ github.repository }}/releases/download/${{ github.event.release.tag_name }}/morpheus-${{ matrix.target }}.zip
7z e morpheus.zip
- name: Test CLI Commands
run: |
./morpheus about
./morpheus build examples/code-gen
./morpheus build examples/code-gen-docs
./morpheus check examples/code-gen
./morpheus check examples/code-gen-docs
68 changes: 38 additions & 30 deletions scripts/local/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,52 @@ const config: Record<string, string> = {

const name = config[process.platform] ?? config.linux;

const binary = "./formatter/ormolu";
type Ops = { fileName: string; url: string };

export const run = async (
f: (bin: string) => Promise<void>,
{ fileName, url }: Ops
) => {
const dir = `__${fileName}__`;
const bin = `./${dir}/${fileName}`;

export const format = async ({ fix, path }: { fix: boolean; path: string }) => {
try {
exec(`mkdir formatter`);
exec(`mkdir ${dir}`);
} catch {}

try {
log("setup ormolu ... \n");

exec(
`curl -o ./formatter/ormolu.zip -LO https://github.com/tweag/ormolu/releases/download/0.5.0.1/${name}`,
"pipe"
);
exec(`cd formatter && unzip ormolu.zip`, "pipe");

exec(`chmod +x ${binary}`, "pipe");

const files = await promisify(glob)(path);

log(`formatting(${files.length} files): ${path} \n\n`);

if (fix) {
exec(`${binary} --color=always --mode=inplace ${files.join(" ")}`);
} else {
exec(
`${binary} --color=always --check-idempotence --mode=check ${files.join(
" "
)}`
);
}

log(`setup ${fileName} ... \n`);
exec(`curl -o ${bin}.zip -LO ${url}`, "pipe");
exec(`cd ${dir} && unzip ${fileName}.zip`, "pipe");
exec(`chmod +x ${bin}`, "pipe");
await f(bin);
log("OK\n", "success");
} catch (e) {
log(e.message + "\n", "error");
exec(`rm -rf ./formatter`);
exec(`rm -rf ${dir}`);
exit(1);
}

exec(`rm -rf ./formatter`);
exec(`rm -rf ${dir}`);
};

export const format = async ({ fix, path }: { fix: boolean; path: string }) =>
run(
async (bin) => {
const files = await promisify(glob)(path);
log(`formatting(${files.length} files): ${path} \n\n`);

if (fix) {
exec(`${bin} --color=always --mode=inplace ${files.join(" ")}`);
} else {
exec(
`${bin} --color=always --check-idempotence --mode=check ${files.join(
" "
)}`
);
}
},
{
fileName: "ormolu",
url: `https://github.com/tweag/ormolu/releases/download/0.5.0.1/${name}`,
}
);

0 comments on commit c37d623

Please sign in to comment.