From fa87edae7a66d79d5bfb4dc55b5dcf737ac986f6 Mon Sep 17 00:00:00 2001 From: Laurence de Bruxelles Date: Thu, 21 Oct 2021 12:36:06 +0100 Subject: [PATCH] Replace Travis CI with GitHub Actions 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 --- .github/workflows/publish.yaml | 63 ++++++++++++++++++++++++++++++++++ .github/workflows/test.yaml | 23 +++++++++++++ .travis.yml | 19 ---------- 3 files changed, 86 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/publish.yaml create mode 100644 .github/workflows/test.yaml delete mode 100644 .travis.yml diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 00000000..70779922 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -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 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 00000000..ca56cf02 --- /dev/null +++ b/.github/workflows/test.yaml @@ -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 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 5ee8def1..00000000 --- a/.travis.yml +++ /dev/null @@ -1,19 +0,0 @@ -language: ruby -cache: - bundler: true - npm: true -before_install: - - nvm install - - nvm use - - gem update --system - - gem install bundler -before_script: - - npm install -deploy: - provider: rubygems - gem: govuk_tech_docs - api_key: - secure: "pFaDlf2VfJAv/EwTFQTdHQFlFRLxtNnipcJyFG0Dvn7itvETKzs5+91gnXQAJuUzGBgXSidHgMkmPTsmWM4k2wbOcHopir9ThSKf0OUtI6o/5GqCU92BpLNJ/Ykhf+wyz9ai6HWX+HN5KRDqpeiuwhraiQjy/tg6lwsauBU8sB80wvUgYYM6oXijHfVwPUkXdhqYTIj20S0M868yYGtf4IInHds8M85TSNor79TFvRd0SFLO7cS+bftqxnNo1mYuBzVXls3POjq59WX+yG8+vS9Sr/tHHuKxw1nho95Fnjf8RYzdxD45osCrXAu3JIbWyJjF6AmQd87zILhdl8n0KNf4tbpFVM+SXVUjMZ2ERvcS1v+nBybVzU3uPwskGZNfWMtCOS401yRF3A21xzNoS916gZrTUSvHjsMcNhzJAZCsEx6MGFVTMzfe5slfWQCPk8k9wBHjyUyC7dl0h5g9qo3jTDnafcpQdnWGOSGgwCxgTaYT1NFfV3M5YpdGevorkOnE6EmWtU67mdtjzRyVvMWc8obqBWdyYnxqrBYKnHDeu/LhtJq3Gvqt/IExwAI8Q1Q7j296hzfmYMcgnETctLNZWoIa4sESDDVMlspcZKqCsrxytDeBFm/yMqVp12S7cjoQbt+fItTl3Bh3BP56j+3fqJlFvTPX4FIKUaaRLy0=" - on: - repo: alphagov/tech-docs-gem - branch: master