OpenHausIO / backend

HTTP API for the OpenHaus SmartHome/IoT solution
https://docs.open-haus.io
6 stars 2 forks source link

Automate releases (GitHub actions) #88

Open mStirner opened 2 years ago

mStirner commented 2 years ago

A quick test with github actions to release new version was semi successful. Release a build & created, but the are error with tagging & body content.

./github/workflows/release.yml:

# This workflow will do a clean install of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Release

on:
  push:
    # Sequence of patterns matched against refs/tags
    tags:
      - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

jobs:
    build:
        #runs-on: [ubuntu-18.04, ubuntu-latest]
        runs-on: ubuntu-latest

        strategy:
            matrix:
                node-version: [16.x]

        steps:
            - uses: actions/checkout@v2     

            - name: get-npm-version
              id: package-version
              uses: martinbeentjes/npm-get-version-action@master

            # node.js setup
            - name: Use Node.js ${{ matrix.node-version }}
              uses: actions/setup-node@v2
              with:
                  node-version: ${{ matrix.node-version }}
                  cache: "npm"

            # run npm commands
            - run: npm install
            - run: npm run build:dist
            - run: grunt compress

            # create changelog
            - name: Changelog
              uses: scottbrenner/generate-changelog-action@master
              id: Changelog
              env:
                REPO: ${{ github.repository }}

            # create release
            - name: release
              uses: actions/create-release@v1
              id: create_release
              with:
                draft: false
                prerelease: false
                release_name: backend-v${{steps.package-version.outputs.current-version}}
                tag_name: foo21ea13
                body: "Test release"
              env:
                GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

            - name: Upload attachment
              uses: actions/upload-release-asset@v1
              env:
                GITHUB_TOKEN: ${{ github.token }}
              with:
                upload_url: ${{ steps.create_release.outputs.upload_url }}
                asset_path: backend-v${{steps.package-version.outputs.current-version}}.tgz
                asset_name: backend-v${{steps.package-version.outputs.current-version}}.tgz
                asset_content_type: application/gzip

#            - name: Attach *.tgz file
#              uses: actions/upload-artifact@v3
#              with:
#                path: backend-v${{steps.package-version.outputs.current-version}}.tgz

actions/create-release@v1 is not maintained any more. When you use ${{ github.ref }} for the tag_name field following error occurs: {"resource":"Release","code":"already_exists","field":"tag_name"}

Something to read:

How to handle "version bumping", tag creating, releasing process.

mStirner commented 1 year ago

Workflow should be: 1) Lint 2) Build 3) Test 4) HTTP API test 5) Release (docker/github)

mStirner commented 8 months ago
name: Release Workflow

on:
  push:
    branches:
      - main

jobs:
  release:
    runs-on: ubuntu-latest
    permissions: write-all

    steps:
      - name: Check out repository
        uses: actions/checkout@v4

      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '16'
      - run: npm ci
      - run: npm run release

      - name: "Read package.json"
        run: echo "PACKAGE_JSON=$(jq -c . < package.json)" >> $GITHUB_ENV

      - uses: ncipollo/release-action@v1        
        with:
          artifacts: "dist/*"
          tag: "v${{ fromJson(env.PACKAGE_JSON).version }}"
          generateReleaseNotes: true
          skipIfReleaseExists: true

https://github.com/mStirner/playground-test-auto-release

Run action only if merge and not rejected/closed. For pushes/merges on dev the "pre-release" flag could be set and the exisiting version release could be updated: https://github.com/marketplace/actions/create-release

The autogenerated release notes are ugly. Wrong order (newest changes should be on top, not bottom). Use "external" other github action to generated release notes, like "scottbrenner/generate-changelog-action@master" ?