From 20d1d8e544622f7c9850489378fbb21a037f43c2 Mon Sep 17 00:00:00 2001 From: Ben Koshy Date: Mon, 2 Aug 2021 22:35:44 +1000 Subject: [PATCH] chore: add github action - publish & tag versions (#322) --- .github/workflows/publish-gem-and-tag.yml | 56 +++++++++++++++++++++++ lib/javascripts/pagy.js | 6 ++- 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/publish-gem-and-tag.yml diff --git a/.github/workflows/publish-gem-and-tag.yml b/.github/workflows/publish-gem-and-tag.yml new file mode 100644 index 000000000..9e1b96ae9 --- /dev/null +++ b/.github/workflows/publish-gem-and-tag.yml @@ -0,0 +1,56 @@ + +# What does this action do? + +# This Github Action allows for: +# (i) the publishing of the gem to ruby gems. +# (ii) automatic tagging of the default branch. +# The action is triggered through a manual action - click and run (i.e. through workflow_dispatch) +# The default branch is assumed. + +# The version number of pagy is located in two distinct files: the lib/pagy.rb file and also the +# lib/javascripts/pagy.js file. + +# Ruby gems publishes the version number located in the pagy.rb file, while we tag the default +# branch using the version located in the pagy.js file. both versions listed in those two file smust be kept +# in sync to avoid confusion. + +name: publish-gem-and-tag +on: + workflow_dispatch: + +jobs: + publish-gem-and-tag: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 # checks out default branch + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.0.0 + - run: bundle install + + - name: publish gem + run: | + mkdir -p $HOME/.gem + touch $HOME/.gem/credentials + chmod 0600 $HOME/.gem/credentials + printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials + gem build *.gemspec + gem push *.gem + env: + GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}" + + - name: Create tag + uses: actions/github-script@v3 + with: + github-token: ${{ github.token }} + script: | + const fs = require("fs") + eval(fs.readFileSync("./lib/javascripts/pagy.js").toString()) + + github.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: `refs/tags/${Pagy.version}`, + sha: context.sha + }) \ No newline at end of file diff --git a/lib/javascripts/pagy.js b/lib/javascripts/pagy.js index bd6f5a7e8..9c777be30 100644 --- a/lib/javascripts/pagy.js +++ b/lib/javascripts/pagy.js @@ -114,4 +114,8 @@ Pagy.waitForMe = Pagy.tid = setTimeout(Pagy.renderNavs, Pagy.delay) } -window.addEventListener('resize', Pagy.waitForMe, true) + +if (typeof window !== "undefined") { + window.addEventListener('resize', Pagy.waitForMe, true) +} +