Skip to content

Commit

Permalink
Release CI
Browse files Browse the repository at this point in the history
  • Loading branch information
harmony7 committed Dec 13, 2022
1 parent 9ce32fa commit 402de0d
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/scripts/pack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# install deps
bundle install

# tag the version
sed -i "s/^ VERSION = .*$/ VERSION = '${VERSION}'/" lib/fastly/version.rb
bundle install

# make a gem (output is always ./pkg)
rake build

# save the output filename to env
PACKAGE_FILENAME=$(cd ./pkg && ls -1 -- *.gem)
echo "PACKAGE_FILENAME=${PACKAGE_FILENAME}" >> "${GITHUB_ENV}"

# move gem to dist
mkdir "${GITHUB_WORKSPACE}/dist"
mv "./pkg/${PACKAGE_FILENAME}" "${GITHUB_WORKSPACE}/dist/${PACKAGE_FILENAME}"
11 changes: 11 additions & 0 deletions .github/scripts/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
echo "Publishing ${PROJECT_NAME} to ${PACKAGE_REPO_NAME}"
echo " Publishing version: ${VERSION}"
echo " Publish tag is ${PUBLISH_TAG}"

# perform publish
if [ "${DRY_RUN}" == "1" ]; then
echo "(dry run)"
else
rake build
gem push ./pkg/"${PACKAGE_FILENAME}"
fi
35 changes: 35 additions & 0 deletions .github/scripts/publish_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Parse the release tag

# strip leading 'release/'
TAG="${GITHUB_REF_NAME#release/}"

# strip leading v
TAG_VALUE="${TAG#v}"

# strip trailing -dry
VERSION="${TAG_VALUE%-dry}"

# detect valid semver
VALID_VERSION=$(npx -y [email protected] "${VERSION}" --field matches)
if [ "${VALID_VERSION}" != "true" ]; then
exit 1
fi

# Detect dry run mode
DRY_RUN=0
if [ "${TAG_VALUE}" != "${VERSION}" ]; then
DRY_RUN=1
fi

# publish tag ('alpha', 'beta', etc.) is used to tag the release
PUBLISH_TAG="$(npx -y [email protected] "${VERSION}" --field preid)"
if [ "${PUBLISH_TAG}" == "undefined" ]; then
PUBLISH_TAG=latest
fi

echo "API_CLIENT_NAME=Ruby"
echo "PROJECT_NAME=fastly-ruby"
echo "PACKAGE_REPO_NAME=RubyGems"
echo "VERSION=${VERSION}"
echo "DRY_RUN=${DRY_RUN}"
echo "PUBLISH_TAG=${PUBLISH_TAG}"
25 changes: 25 additions & 0 deletions .github/scripts/release_body.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
printf '%s' "## ${API_CLIENT_NAME} API client v${VERSION}"

if [ "${DRY_RUN}" == "1" ]; then
printf '%s' " (dry run)"
fi

echo ""

# add a newline
echo ""

CODE_PATH=${CODE_PATH:-./}
G_CODE=$(jq -r .G "${CODE_PATH}/sig.json")
D_CODE=$(jq -r .D "${CODE_PATH}/sig.json")

PACKAGE_FILESIZE=$(ls -lh "${GITHUB_WORKSPACE}/dist/${PACKAGE_FILENAME}" | awk '{print $5}')B

echo "Artifact"
echo " ${PACKAGE_FILENAME} (${PACKAGE_FILESIZE})"
echo ""
echo "Generated on: $(date)"
echo "G-code: ${G_CODE}, D-code: ${D_CODE}"
if [ "${PUBLISH_TAG}" != "latest" ]; then
echo "Pre-release Tag: ${PUBLISH_TAG}"
fi
59 changes: 59 additions & 0 deletions .github/workflows/ci-release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Release CI
on:
push:
tags:
# This looks like a regex, but it's actually a filter pattern
# see https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#filter-pattern-cheat-sheet
- 'release/v?[0-9]*'

env:
GITHUB_REF_NAME: ${{ github.ref_name }}

jobs:
publish:
name: Publish to RubyGems
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
path: main
- name: Set up environment variables
run: ./.github/scripts/publish_env.sh >> $GITHUB_ENV
working-directory: ./main
shell: bash
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.1'
bundler-cache: true
- name: Pack API client
run: ./.github/scripts/pack.sh
working-directory: ./main
shell: bash
- name: Auth with RubyGems
run: |
mkdir -p ~/.gem
echo ":rubygems_api_key: ${{ secrets.RUBYGEMS_PUBLISH_TOKEN }}" > ~/.gem/credentials
chmod 600 ~/.gem/credentials
shell: bash
- name: Publish API client
run: ./.github/scripts/publish.sh
working-directory: ./main
shell: bash
- name: Write release body file
run: CODE_PATH=./main ./main/.github/scripts/release_body.sh > ./dist/release_body.txt
shell: bash
- name: Create release (dry run)
if: ${{ env.DRY_RUN == '1' }}
run: cat ./dist/release_body.txt
- name: Create GitHub release
if: ${{ env.DRY_RUN != '1' }}
uses: softprops/action-gh-release@v1
with:
name: v${{ env.VERSION }}
body_path: ./dist/release_body.txt
files: |
./dist/${{ env.PACKAGE_FILENAME }}
draft: false
prerelease: ${{ env.PUBLISH_TAG != 'latest' }}

0 comments on commit 402de0d

Please sign in to comment.