Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate releases (GitHub actions) #88

Open
mStirner opened this issue Mar 27, 2022 · 2 comments
Open

Automate releases (GitHub actions) #88

mStirner opened this issue Mar 27, 2022 · 2 comments
Labels

Comments

@mStirner
Copy link
Member

mStirner commented Mar 27, 2022

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 added a commit to mStirner/backend that referenced this issue Mar 27, 2022
@mStirner
Copy link
Member Author

@mStirner
Copy link
Member Author

mStirner commented Feb 14, 2024

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" ?

@mStirner mStirner added the ci cd label May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant