Skip to content

Commit

Permalink
Replace Travis CI with GitHub Actions
Browse files Browse the repository at this point in the history
We want to use GitHub Actions as the tech docs template's continuous
integration/continuous deployment service. This commit removes
`.travis.yml` and adds equivalent workflows, `test.yaml` and
`publish.yaml`.

The script to publish to RubyGems was copied from the
discourse/publish-rubygems-action [[1]], with a modification to use the
github-actions[bot] user for tagging the release following suggestion from
fregante/setup-git-user action [[2]]. We avoid using the action directly
in accordance with the guidelines in the GDS Way [[3]].

[1]: https://github.com/discourse/publish-rubygems-action/blob/b55d7b9/entrypoint.sh
[2]: https://github.com/fregante/setup-git-user/blob/5ede2be/index.js
[3]: https://gds-way.cloudapps.digital/standards/source-code.html#using-github-actions-and-workflows

Use GitHub Actions bot account for creating release tags
  • Loading branch information
lfdebrux committed Oct 21, 2021
1 parent 209a7ec commit fa87eda
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 19 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Publish

on:
push:
branches:
- master
workflow_dispatch:

concurrency: rubygems

jobs:
deploy:
name: Publish Ruby Gem
environment: rubygems
permissions:
contents: write # needed to be able to tag the release
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- uses: actions/setup-node@v2
with:
cache: 'npm'
node-version: '14'

- uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- name: Check if new version to release
id: gem_version
run: |
gem_version=$(ruby -r rubygems -e "puts Gem::Specification::load('$(ls *.gemspec)').version")
echo "::set-output name=gem_version::$gem_version"
if git fetch origin "refs/tags/v$gem_version" >/dev/null 2>&1
then
echo "Tag 'v$gem_version' already exists"
echo "::set-output name=new_version::false"
else
echo "::set-output name=new_version::true"
fi
- name: Publish
if: ${{ steps.gem_version.outputs.new_version == 'true' }}
env:
RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
GEM: govuk_tech_docs
run: |
mkdir -p ~/.gem
cat << EOF > ~/.gem/credentials
---
:rubygems_api_key: ${RUBYGEMS_API_KEY}
EOF
chmod 0600 ~/.gem/credentials
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
bundle exec rake release
23 changes: 23 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test

on: [push, pull_request]

jobs:
test:
name: Test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- uses: actions/setup-node@v2
with:
node-version: '14'
cache: 'npm'

- uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- name: Run tests
run: bundle exec rake
19 changes: 0 additions & 19 deletions .travis.yml

This file was deleted.

0 comments on commit fa87eda

Please sign in to comment.