diff --git a/.github/actions/changelog/Dockerfile b/.github/actions/changelog/Dockerfile new file mode 100644 index 000000000..f26b02a60 --- /dev/null +++ b/.github/actions/changelog/Dockerfile @@ -0,0 +1,6 @@ +FROM ruby:2 + +WORKDIR /github/workspace +COPY ./entrypoint.rb /entrypoint.rb +RUN chmod +x /entrypoint.rb +ENTRYPOINT [ "/entrypoint.rb" ] diff --git a/.github/actions/changelog/entrypoint.rb b/.github/actions/changelog/entrypoint.rb new file mode 100644 index 000000000..20506c5fe --- /dev/null +++ b/.github/actions/changelog/entrypoint.rb @@ -0,0 +1,21 @@ +#!/usr/bin/env ruby + +version = (ENV['REF'] || ENV['GITHUB_REF'] || '').sub(%r{\Arefs/tags/v}, '') +log = File.read(ENV['CHANGELOG'] || Dir.glob('CHANGELOG*').first) +rlsfile = ENV['RELEASE_FILE'] || '/github/home/.releasenotes' + +match = /^#\s*\[#{version}\]\s+-\s+(?.+?)\r?\n(?<body>.*?)\r?\n#/ms.match(log) +unless match + puts "No Changelog notes found for v#{version}" + exit 78 +end + +title = "Release: v#{version} (#{match.named_captures['title'].strip})" +body = match.named_captures['body'].strip +notes = "#{title}\n\n#{body}" + +puts "Release Notes for v#{version}:" +puts "" +puts notes + +File.open(rlsfile, 'w') {|f| f.write(notes) } diff --git a/.github/actions/install/Dockerfile b/.github/actions/install/Dockerfile new file mode 100644 index 000000000..e0350aa64 --- /dev/null +++ b/.github/actions/install/Dockerfile @@ -0,0 +1,3 @@ +FROM ruby:2 +ENV BUNDLE_PATH=/github/home/.bundle +ENTRYPOINT sh -c "bundle install" diff --git a/.github/actions/package/Dockerfile b/.github/actions/package/Dockerfile new file mode 100644 index 000000000..311254bea --- /dev/null +++ b/.github/actions/package/Dockerfile @@ -0,0 +1,3 @@ +FROM ruby:2 +ENV BUNDLE_PATH=/github/home/.bundle +ENTRYPOINT sh -c "bundle exec rake gem && bundle exec rake install" diff --git a/.github/actions/release/Dockerfile b/.github/actions/release/Dockerfile new file mode 100644 index 000000000..b7f086585 --- /dev/null +++ b/.github/actions/release/Dockerfile @@ -0,0 +1,16 @@ +FROM alpine:latest + +LABEL "com.github.actions.name"="GitHub Release" +LABEL "com.github.actions.description"="Create a GitHub release" +LABEL "com.github.actions.icon"="command" +LABEL "com.github.actions.color"="blue" +LABEL "maintainer"="Loren Segal <lsegal@soen.ca>" + +RUN apk add --no-cache -U \ + --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing \ + hub git + +WORKDIR /github/workspace +COPY ./entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh +ENTRYPOINT [ "/entrypoint.sh" ] diff --git a/.github/actions/release/entrypoint.sh b/.github/actions/release/entrypoint.sh new file mode 100644 index 000000000..9f4214f8e --- /dev/null +++ b/.github/actions/release/entrypoint.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +export GITHUB_TOKEN=${RELEASE_TOKEN:-$GITHUB_TOKEN} +export TAG=${GITHUB_REF#refs/tags/} + +hub release create -a $ARTIFACT -F ${RELEASE_FILE:-/github/home/.releasenotes} $TAG diff --git a/.github/actions/test/Dockerfile b/.github/actions/test/Dockerfile new file mode 100644 index 000000000..8a22a2ce2 --- /dev/null +++ b/.github/actions/test/Dockerfile @@ -0,0 +1,3 @@ +FROM ruby:2 +ENV BUNDLE_PATH=/github/home/.bundle +ENTRYPOINT sh -c "bundle exec rake" diff --git a/.github/main.workflow b/.github/main.workflow new file mode 100644 index 000000000..c2c66ac80 --- /dev/null +++ b/.github/main.workflow @@ -0,0 +1,42 @@ +workflow "Build, Test, and Publish" { + on = "push" + resolves = ["Package Gem", "Publish Gem", "Create GitHub Release"] +} + +action "Install" { + uses = "./.github/actions/install" +} + +action "Test" { + needs = "Install" + uses = "./.github/actions/test" +} + +action "Package Gem" { + needs = "Test" + uses = "./.github/actions/package" +} + +action "On Tag" { + needs = "Package Gem" + uses = "actions/bin/filter@master" + args = "tag v*" +} + +action "Release Notes" { + needs = "On Tag" + uses = "./.github/actions/changelog" +} + +action "Create GitHub Release" { + needs = "Release Notes" + uses = "./.github/actions/release" + secrets = ["RELEASE_TOKEN"] +} + +action "Publish Gem" { + needs = "On Tag" + uses = "scarhand/actions-ruby@master" + args = "push *.gem" + secrets = ["RUBYGEMS_AUTH_TOKEN"] +}