.github/workflows/release.yml-old

Summary

Maintainability
Test Coverage
name: Build, Generate Ruby Gem and Release

on:
  push:
    tags:
      - 'v*.*.*'

jobs:
  build:

    env:
      RAILS_ENV: production
      NODE_ENV: production
      BUNDLE_WITHOUT: development:test

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
    - name: Set up Ruby
      uses: ruby/setup-ruby@v1
      with:
        ruby-version: 3.1.0

    - uses: actions/cache@v3
      with:
        path: vendor/bundle
        key: ${{ runner.os }}-production-gems-${{ hashFiles('**/Gemfile.lock') }}
        restore-keys: |
          ${{ runner.os }}-production-gems-

    - name: Bundle install
      run: |
        bundle config path vendor/bundle
        bundle install --jobs 4 --retry 3

    - name: Get yarn cache directory path
      id: production-yarn-cache-dir-path
      run: echo "::set-output name=dir::$(yarn cache dir)"

    - uses: actions/cache@v3
      id: production-yarn-cache
      with:
        path: ${{ steps.production-yarn-cache-dir-path.outputs.dir }}
        key: ${{ runner.os }}-production-yarn-${{ hashFiles('**/yarn.lock') }}
        restore-keys: |
          ${{ runner.os }}-production-yarn-

    - name: Yarn install
      run: yarn install

    - name: Yarn check integrity
      run: yarn check --integrity

    - name: Symlink avo packages
      run: bundle exec rails avo:sym_link

    - name: Build assets
      run: |
        yarn prod:build:js
        yarn prod:build:css

    - name: Build gem
      run: bundle exec rails build

    - name: Get gem version
      id: gem_version
      run: |
        echo "::set-output name=tag::$(sed "s|refs/tags/v||" <<< ${{ github.ref }})"

    - name: Get release notes
      uses: actions/github-script@v6
      id: get_release_notes
      with:
        script: |
          const {data: releases} = await github.rest.repos.listReleases({
            owner: context.repo.owner,
            repo: context.repo.repo,
          });
          return releases.find((r) => r.draft)?.body || "No draft release found."

    - name: Create Release
      id: create_release
      if: ${{steps.get_release_notes.outputs.result != ''}}
      uses: actions/create-release@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        tag_name: ${{ github.ref }}
        release_name: Release ${{ github.ref }}
        body: |
          ${{fromJson(steps.get_release_notes.outputs.result)}}
        draft: false
        prerelease: false

    - name: Upload Release Asset
      id: upload-release-asset
      uses: actions/upload-release-asset@v1
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
        asset_path: pkg/avo-${{steps.gem_version.outputs.tag}}.gem
        asset_name: avo-${{steps.gem_version.outputs.tag}}.gem
        asset_content_type: application/x-tar

    - name: Publish to rubygems.org
      id: publish-to-rubygems-package-registry
      env:
        RUBYGEMS_TOKEN: ${{ secrets.RUBYGEMS_TOKEN }}
      run: |
        mkdir ~/.gem
        touch ~/.gem/credentials
        chmod 600 ~/.gem/credentials
        echo ":rubygems_api_key: ${RUBYGEMS_TOKEN}" >> ~/.gem/credentials
        gem push --host https://rubygems.org/ ./pkg/avo-${{steps.gem_version.outputs.tag}}.gem

    - name: Publish to GitHub Package Registry
      id: publish-to-github-package-registry
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      run: |
        echo ":github: Bearer ${GITHUB_TOKEN}" >> ~/.gem/credentials
        gem push --key github --host https://rubygems.pkg.github.com/avo-hq ./pkg/avo-${{steps.gem_version.outputs.tag}}.gem

    - name: Publish release on avohq.io
      run: curl https://avohq.io/releases/refresh_releases