atc0005 / todo

A collection of TODO items not specific to any one project
MIT License
0 stars 0 forks source link

Begin testing automatic build & upload options for Go projects #45

Closed atc0005 closed 1 year ago

atc0005 commented 1 year ago

This workflow looks promising:

https://github.com/sqlitebrowser/sqlitebrowser/blob/continuous/.github/workflows/cppcmake.yml

Current contents of workflow file:

name: CI

on:
  push:
    branches: ['*']
    tags:
    paths_ignore: ['docs/**']
  pull_request:
    branches: ['*']
  release:
    types: ['created']

defaults:
  run:
    shell: bash

jobs:
  build:
    name: ${{ matrix.os }} - SQLCipher ${{ matrix.sqlcipher }}
    runs-on: ${{ matrix.os }}
    strategy:
      fail-fast: true
      matrix:
        os: [ubuntu-20.04]
        sqlcipher: ["0", "1"]
    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - name: Install dependencies
      run: |
           sudo apt-get update
           sudo apt-get install qttools5-dev libqt5scintilla2-dev libqcustomplot-dev libsqlite3-dev libqt5svg5 libsqlcipher-dev
    - name: Configure CMake
      run: |
           cmake --version
           cmake -S . -B build -DCMAKE_BUILD_TYPE=Release \
                -DCMAKE_INSTALL_PREFIX=${PWD}/install \
                -DCPACK_PACKAGE_DIRECTORY=${PWD}/package \
                -DENABLE_TESTING=ON \
                -Dsqlcipher=${{ matrix.sqlcipher }}
    - name: Run make
      run: cmake --build build --config Release -j --target install
    - name: run tests
      run: ctest -V -C Release --test-dir build
    - name: Package
      run: |
           cmake --build build --config Release -j --target package
           cmake -E remove_directory package/_CPack_Packages
    - name: Upload package
      uses: actions/upload-artifact@master
      with:
        name: pkg-${{ matrix.os }}-sqlcipher${{ matrix.sqlcipher }}
        path: package
    - name: Upload to release page
      if: github.event_name == 'release'
      env:
        GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
        TAG: ${{ github.event.release.tag_name }}
        UPLOAD_URL: ${{ github.event.release.upload_url }}
      run: |
              # Do try this at home! The REST API is documented at
              # https://docs.github.com/en/free-pro-team@latest/rest and you can get a personal
              # access token at https://github.com/settings/tokens
              # (set GITHUB_TOKEN to "bearer abcdef1234")
              # you can get the UPLOAD_URL with a short bash snippet; make sure to set the env var TAG:
              # UPLOAD_URL=$(curl -H 'Accept: application/vnd.github.v3+json' $GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases/tags/$TAG | jq -r .upload_url)
              UPLOAD_URL=${UPLOAD_URL%\{*} # remove "{name,label}" suffix
              for pkg in package/*.*; do
                NAME=$(basename $pkg)
                MIME=$(file --mime-type $pkg|cut -d ' ' -f2)
                curl -X POST -H "Accept: application/vnd.github.v3+json" -H "Authorization: token $GITHUB_TOKEN" -H "Content-Type: $MIME" --data-binary @$pkg $UPLOAD_URL?name=$NAME
              done
atc0005 commented 1 year ago

This is also covered in the Go for DevOps book.

atc0005 commented 1 year ago

I've been giving some thought to the proposal mentioned here:

https://gist.github.com/steinwaywhw/a4cd19cda655b8249d908261a62687f8?permalink_comment_id=3936277#gistcomment-3936277

a note (for your repositories)

I advise using consistent file-names. I.E. don't include a versioning in the filename. I know it sounds weird, but bear with me* for a second.

You know the .../releases/latest syntax right? did you know you can also use it to download files as well? (and not just to redirect to the latest release on Github?)

Here, try this URL for example: https://github.com/ytdl-org/youtube-dl/releases/latest/download/youtube-dl.exe.

this reduces the need to walk through Github-Releases API entirely! and simplify stuff for users and also web-services that crawls your repository (in-case you have a somewhat popular product :] ). You don't to maintain any kind of backend or domain at all and relink to to the latest binaries (for example: http://youtube-dl.org/downloads/latest/youtube-dl.exe). it is handled by github releases!

you can always include the version in a file named version.txt, or any meta-data, really. keep a consistent file-name here too.

got the idea from https://github.com/yt-dlp/yt-dlp#update

This would make it a lot easier for local deployment tooling to deploy updated assets directly from project repos using the /releases/latest URL pattern.

atc0005 commented 1 year ago

See also: