.github/workflows/release.yml
name: Tag & Release Package
on:
push:
branches:
- main
jobs:
checks:
runs-on: ubuntu-latest
outputs:
pre_release: ${{ steps.versioning.outputs.pre_release }}
upgraded: ${{ steps.versioning.outputs.upgraded }}
package_version: ${{ steps.versioning.outputs.package_version }}
release_message: ${{ steps.versioning.outputs.release_message }}
steps:
- uses: actions/checkout@v2
- name: Set up Ruby 2.7
uses: actions/setup-ruby@v1
with:
ruby-version: 2.7
- name: Install bundler
run: gem install bundler
- name: Cache dependencies
uses: actions/cache@v2
with:
path: vendor/bundle
key: ${{ runner.os }}-gem-${{ hashFiles('**/rails-cloud-tasks.gemspec') }}-2.7
- name: Install dependencies
run: |
bundle config set without 'development test'
bundle install
- name: Fetching Tags
run: git fetch -t
- name: Detect version upgrade
id: versioning
run: |
pkg='rails-cloud-tasks'
package_version=$(bundle info $pkg | grep -o "$pkg \(.*\)" | sed "s/$pkg (\(.*\))/\1/")
echo "::set-output name=package_version::"$package_version
upgraded=$(git tag --list | grep -q "${package_version}$" && echo "false" || echo "true")
echo "::set-output name=upgraded::"$upgraded
pre_release=$([[ $package_version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] && echo "false" || echo "true")
echo "::set-output name=pre_release::"$pre_release
release_message=$(git log HEAD ^$(git describe --tags `git rev-list --tags --max-count=1`) --pretty=format:'* %C(green)%h%C(reset) %s')
echo "::set-output name=release_message::"$release_message
release:
runs-on: ubuntu-latest
needs: checks
if: needs.checks.outputs.upgraded == 'true'
steps:
- uses: actions/checkout@v2
- name: Set up Ruby 2.7
uses: actions/setup-ruby@v1
with:
ruby-version: 2.7
- name: Install bundler
run: gem install bundler
- name: Cache dependencies
uses: actions/cache@v2
with:
path: vendor/bundle
key: ${{ runner.os }}-gem-${{ hashFiles('**/rails-cloud-tasks.gemspec') }}-2.7
- name: Install dependencies
run: |
bundle config set without 'development test'
bundle install
- name: Create Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.checks.outputs.package_version }}
release_name: Release ${{ needs.checks.outputs.package_version }}
body: |
${{ needs.checks.outputs.release_message }}
draft: false
prerelease: ${{ needs.checks.outputs.pre_release }}
- name: Build package
run: bundle exec gem build -o rails-cloud-tasks.gem
- name: Setup RubyGems credentials
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:rubygems: ${{ secrets.RUBYGEMS_API_TOKEN }}\n" > $HOME/.gem/credentials
- name: Push package
run: gem push --key rubygems rails-cloud-tasks.gem