diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml index f874a49..8ebbadd 100644 --- a/.github/workflows/pre-release.yml +++ b/.github/workflows/pre-release.yml @@ -25,8 +25,8 @@ jobs: if: github.event_name == 'pull_request' steps: - uses: actions/checkout@v3 - - uses: haskell/actions/hlint-setup@v1 - - uses: haskell/actions/hlint-run@v2 + - uses: haskell-actions/hlint-setup@v1 + - uses: haskell-actions/hlint-run@v2 fourmolu: runs-on: ubuntu-latest @@ -39,118 +39,82 @@ jobs: pattern: | */**/*.hs - create_release: - name: Create Github Release - runs-on: ubuntu-latest - permissions: write-all - steps: - - name: Check out code - uses: actions/checkout@v4 - - - name: Create short commit sha - run: echo "GITHUB_SHA_SHORT=$(echo $GITHUB_SHA | cut -c 1-10)" >> $GITHUB_ENV - - - name: Create Pre-release - id: create_release - uses: actions/create-release@v1.1.4 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - name: Pre-release ${{ env.GITHUB_SHA_SHORT }} - tag_name: Pre-release-${{ env.GITHUB_SHA_SHORT }} - release_name: Pre-release ${{ github.ref }} - draft: true - prerelease: true - - - name: Output Release URL File - run: echo "${{ steps.create_release.outputs.upload_url }}" > release_url.txt - - - name: Save Release URL File for publish - uses: actions/upload-artifact@v3 - with: - name: release_url - path: release_url.txt - - build_artifact: - needs: [create_release] - name: ${{ matrix.os }}/GHC ${{ matrix.ghc }}/${{ github.ref }} + build-binaries: + name: Build and upload binaries (${{ matrix.os }}) runs-on: ${{ matrix.os }} strategy: - # Don't fail fast because we test a lot of versions and it's - # good to know which ones work and which ones don't - fail-fast: false matrix: - os: [ubuntu-latest, macOS-latest, windows-latest] - ghc: - - "9.6.5" - cabal: ["latest"] - + include: + - os: ubuntu-latest + extra-build-args: -j2 + - os: macos-latest + extra-build-args: -j3 + - os: windows-latest + extra-build-args: -j2 steps: - - name: Check out code - uses: actions/checkout@v4 + # SETUP + - name: Checkout repo + uses: actions/checkout@v3 - - name: Setup Haskell - uses: haskell/actions/setup@v2 - id: setup-haskell-cabal + - uses: haskell/actions/setup@v2 with: - ghc-version: ${{ matrix.ghc }} - cabal-version: ${{ matrix.cabal }} - - - name: Freeze - run: | - cabal freeze + ghc-version: '9.6.5' + # CACHING - name: Cache ~/.cabal/store - uses: actions/cache@v4 + uses: actions/cache@v3 with: path: ${{ steps.setup-haskell-cabal.outputs.cabal-store }} key: ${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('cabal.project.freeze') }} - - name: Build binary + - name: Build binary (${{ runner.os }}) + shell: bash run: | - mkdir dist - cabal install exe:asmh --install-method=copy --overwrite-policy=always --installdir=dist + mkdir "$(pwd)/asmh-${{ runner.os }}" + cabal install exe:asmh --install-method=copy --overwrite-policy=always --installdir="$(pwd)/asmh-${{ runner.os }}" --ghc-options=-O2 ${{ matrix.extra-build-args }} - # See Note [environment variables] - - if: matrix.os == 'windows-latest' - name: Set binary path name on Windows - run: echo "BINARY_PATH=./dist/asmh.exe" >> $env:GITHUB_ENV + # UPLOAD BINARIES + - name: Compress dirs (Unix) + if: matrix.os != 'windows-latest' + shell: bash + run: zip -r asmh-${{ runner.os }}.zip asmh-${{ runner.os }} - # See Note [environment variables] - - if: matrix.os != 'windows-latest' - name: Set binary path name not on Windows - run: echo "BINARY_PATH=./dist/asmh" >> "$GITHUB_ENV" + - name: Compress dirs (Windows) + if: matrix.os == 'windows-latest' + shell: pwsh + run: Compress-Archive -Path "asmh-${{ runner.os }}" -DestinationPath "asmh-${{ runner.os }}.zip" - - name: Compress binary - uses: svenstaro/upx-action@2.3.0 - with: - file: ${{ env.BINARY_PATH }} - - name: Load Release URL File from release job - uses: actions/download-artifact@v3 + - name: Upload artifact (${{ runner.os }}) + uses: actions/upload-artifact@v3 with: - name: release_url - path: release_url + name: asmh-${{ runner.os }} + path: asmh-${{ runner.os }}.zip + if-no-files-found: error + + pre-release: + name: "Pre Release" + needs: build-binaries + if: github.event_name != 'pull_request' + permissions: + contents: write + runs-on: "ubuntu-latest" + steps: + - uses: actions/download-artifact@v3 - # See Note [environment variables] - - if: matrix.os == 'windows-latest' - name: Get Release File Name & Upload URL on Widows - run: | - echo "upload_url=$(cat release_url/release_url.txt)" >> $env:GITHUB_ENV + - name: Check artifacts + run: ls -R - # See Note [environment variables] - - if: matrix.os != 'windows-latest' - name: Get Release File Name & Upload URL not on Widows - run: | - echo "upload_url=$(cat release_url/release_url.txt)" >> $GITHUB_ENV + - name: Create short commit sha + run: echo "GITHUB_SHA_SHORT=$(echo $GITHUB_SHA | cut -c 1-10)" >> $GITHUB_ENV - - name: Upload Release Asset - id: upload-release-asset - uses: actions/upload-release-asset@v1.0.2 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Release + uses: softprops/action-gh-release@v1 with: - upload_url: ${{ env.upload_url }} - asset_path: ${{ env.BINARY_PATH }} - asset_name: asmh-${{ runner.os }}-ghc-${{ matrix.ghc }}${{ env.EXT }} - asset_content_type: application/octet-stream + name: Pre-release ${{ env.GITHUB_SHA_SHORT }} + draft: false + prerelease: true + tag_name: Pre-release-${{ env.GITHUB_SHA_SHORT }} + fail_on_unmatched_files: true + generate_release_notes: true + files: 'asmh-**/asmh-*' diff --git a/app/CmdOptions.hs b/app/CmdOptions.hs index 658cbd7..4b08896 100644 --- a/app/CmdOptions.hs +++ b/app/CmdOptions.hs @@ -8,28 +8,43 @@ where import Data.Version (showVersion) import GitHash -import OptEnvConf -import Path +import Options.Applicative import Paths_asmh (version) newtype Options = Options - { sourceCodeFile :: Path Abs File + { sourceCodeFile :: FilePath } -instance HasParser Options where - settingsParser = do - val <- - filePathSetting - [ help "the file to compile" - , argument - ] - pure $ Options val - runCmdOptions :: IO Options -runCmdOptions = runSettingsParser version descriptionString +runCmdOptions = execParser options + +options :: ParserInfo Options +options = + info + (opts <**> helper) + ( fullDesc + <> header headerString + <> progDesc "i8086 assembler" + <> footer + "source code: https://github.com/0rphee/asmh" + <> failureCode 64 + ) where - descriptionString = concat ["Run asmh - v", showVersion version, gitInfoString] + headerString = "asmh - v" <> versionString +opts :: Parser Options +opts = + Options + <$> strArgument + ( metavar "FILENAME" + <> help "Input file" + <> action "file" + ) + <**> simpleVersioner versionString + +versionString :: String +versionString = showVersion version <> gitInfoString + where gitInfoString = case $$tGitInfoCwdTry of Right gi -> concat @@ -37,9 +52,5 @@ runCmdOptions = runSettingsParser version descriptionString , giBranch gi , "@" , giHash gi - , " (" - , show $ giCommitCount gi - , " commits in HEAD" - , ")" ] _ -> "" diff --git a/app/Main.hs b/app/Main.hs index 3768d11..a42a2f1 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -10,8 +10,8 @@ import Bin main :: IO () main = do - -- (Options sourceCodeFile) <- runCmdOptions - -- putStrLn $ "FILEPATH: " <> toFilePath sourceCodeFile + (Options sourceCodeFile) <- runCmdOptions + putStrLn $ "FILEPATH: " <> sourceCodeFile assemblyCode <- T.readFile "asm/colors.asm" -- let assemblyCode = -- T.unlines diff --git a/asmh.cabal b/asmh.cabal index e6741f8..4b4d67c 100644 --- a/asmh.cabal +++ b/asmh.cabal @@ -82,10 +82,11 @@ executable asmh bytestring, cereal, githash, - opt-env-conf, + optparse-applicative, path, text, +-- opt-env-conf, test-suite asmh-test import: common-options