-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from fac/devp/v2
Version v2 - Change: Don't pass the gem host around as an environment variable, extract from the gemspec. - Change: Don't pass gem keys around in environment variables anymore. Use the installed creds by key name. - Add: input key to set the key name in gem credentials to use. - Change: Release/pre-release inputs collapsed into single pre-release input. Push is either release or pre-release version, can't do both (or none!) in the same call anymore. - Add: Add linter for action code. - Change: tag-release input renamed to just tag. - Change: Use command line args instead of env variables for the internal command.
- Loading branch information
Showing
6 changed files
with
132 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Lint Code Base | ||
# https://help.github.com/en/articles/workflow-syntax-for-github-actions | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
linter: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
with: | ||
ref: ${{ github.head_ref }} | ||
fetch-depth: 0 # Full history to get a proper list of changed files within `super-linter` | ||
|
||
- name: Lint Code Base | ||
uses: github/super-linter@v3 | ||
env: | ||
VALIDATE_ALL_CODEBASE: false | ||
VALIDATE_BASH: true | ||
VALIDATE_YAML: true | ||
DEFAULT_BRANCH: main | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,11 @@ | |
|
||
## Description | ||
|
||
Action to push gems to a gem cutter compatible repository. Probably RubyGems or GitHub Packages. It expects the authentication to have already been setup, using the environment variables GEM_HOST and GEM_HOST_API_KEY. See [fac/ruby-gem-setup-github-packages-action](https://github.com/fac/ruby-gem-setup-github-packages-action) for an action to set this up for you to push to GitHub. | ||
Action to push gems to a gem cutter compatible repository. Basically RubyGems or GitHub Packages. It expects the authentication to have already been setup, `~/.gem/credentials` contains a token for the repo and you know the name of the key. | ||
See [fac/ruby-gem-setup-github-packages-action](https://github.com/fac/ruby-gem-setup-github-packages-action) for an action to set this up for you. It is actually pretty easy if pushing to the same repo. | ||
|
||
If the gem version already exists in the repo the action will no-op and still set a success status. This makes it easier to integrate into workflows, safe to re-run (intentionally or accidentally) and wont push duplicate/replacement packages. | ||
It will still raise an error visible in the summary, letting you know the version already exists. | ||
|
||
## Usage | ||
|
||
|
@@ -16,38 +18,28 @@ Build and push all new version of the gem: | |
|
||
```yaml | ||
steps: | ||
# Setup ruby environment | ||
- uses: actions/checkout@v2 | ||
- uses: ruby/setup-ruby@v1 # .ruby-version | ||
with: | ||
bundler-cache: true # bundle install and cache | ||
bundler-cache: true # bundle install | ||
- run: bundle exec rake build | ||
|
||
- name: Build Gem | ||
shell: bash | ||
run: bundle exec rake build | ||
|
||
- name: Setup GPR | ||
uses: fac/ruby-gem-setup-github-packages-action@v1 | ||
- uses: fac/ruby-gem-setup-github-packages-action@v2 | ||
with: | ||
token: ${{ secrets.github_token }} | ||
|
||
- name: Push Gem | ||
uses: fac/ruby-gem-push-action@v1 | ||
- uses: fac/ruby-gem-push-action@v2 | ||
with: | ||
key: github | ||
``` | ||
If you want to use a different gem host or key: | ||
```yaml | ||
- name: Push Gem | ||
uses: fac/ruby-gem-push-action@v1 | ||
env: | ||
gem_host: http://gems.example.com | ||
gem_host_api_key: ${{ secrets.EXAMPLE_API_KEY }} | ||
``` | ||
Note that the ruby-gem-push-action will push to the host given in the gemspec. The token needs to match. Trying to push to a different host will fail. | ||
### Separate release and pre-release workflow | ||
You probably don't want to push all versions from any branch. More likely you would want to push release versions from your default branch (e.g. main) and pre-release from PR builds. To help with this the release and pre-release inputs can be used: | ||
By default, the action only acts on non-pre-release versions, and prints a message if it thinks the gem has a pre-release version number. If you set the input option `pre-release: true`, then it will only act on pre-release versions, and will skip over regular versions. That way, you can have 2 calls to the action, using the workflow to decide the logic. | ||
|
||
Say you want to push release versions from your default branch (main) and pre-release versions from PR builds: | ||
|
||
```yaml | ||
name: Gem Build and Release | ||
|
@@ -69,32 +61,32 @@ jobs: | |
release: | ||
name: Gem / Release | ||
needs: test | ||
needs: test # Only release IF the tests pass | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: ruby/setup-ruby@v1 | ||
- run: bundle exec rake build | ||
- name: Build Gem | ||
run: bundle exec rake build | ||
|
||
- name: Setup GPR | ||
uses: fac/ruby-gem-setup-github-packages-action@v1 | ||
# Setup repo auth | ||
- uses: fac/ruby-gem-setup-github-packages-action@v2 | ||
with: | ||
token: ${{ secrets.github_token }} | ||
# Release production gem version from default branch | ||
- name: Push Release Gem | ||
- name: Release Gem | ||
if: github.ref == 'refs/heads/main' | ||
uses: fac/ruby-gem-push-action@v1 | ||
uses: fac/ruby-gem-push-action@v2 | ||
with: | ||
key: github | ||
# PR branch builds will release pre-release gems | ||
- name: Push Pre-Release Gem | ||
- name: Pre-Release Gem | ||
if: github.ref != 'refs/heads/main' | ||
uses: fac/ruby-gem-push-action@v1 | ||
uses: fac/ruby-gem-push-action@v2 | ||
with: | ||
release: false | ||
key: github | ||
pre-release: true | ||
``` | ||
|
||
|
@@ -103,31 +95,26 @@ The release job runs if the tests pass, we always package the gem to test that w | |
|
||
## Inputs | ||
|
||
### package-glob | ||
### gem-glob | ||
|
||
File glob to match the gem file to push. The default `pkg/*.gem` picks up gems built using `bundle exec rake build`. You may need to set this if your your gem builds another way. | ||
|
||
```yaml | ||
- name: Push Gem | ||
uses: fac/ruby-gem-push-action@v1 | ||
with: | ||
package-glob: build/special.gem | ||
gem-glob: build/special.gem | ||
``` | ||
|
||
### release | ||
|
||
Whether to push new release versions of the gem. Defaults to true. | ||
|
||
### pre-release | ||
|
||
Whether to push new pre-release versions of the gem. Defaults to true. | ||
Whether to push new pre-release versions of the gem and ignore releases, instead of the normal, push prod releases but ignore pre-release. | ||
|
||
### tag-release | ||
### tag | ||
|
||
When true (the default), after pushing a new gem version tag the repo with | ||
the version number prefixed with `v`. e.g. after pushing version `0.1.0`, the | ||
tag will be `v0.1.0`. This is the same behavior as `gem tag`, but internally | ||
implemented to work with older gem versions. | ||
tag will be `v0.1.0`. This is the same behavior as `gem tag`. (Internally | ||
implemented to work with older gem versions and around bugs that caused tags for failed pushes, which then blocked re-pushing. | ||
|
||
The tag commit and push will be made as the author of the commit being tagged. | ||
|
||
|
@@ -139,14 +126,7 @@ If we pushed a gem to the repository, this will be set to the version pushed. | |
|
||
## Environment Variables | ||
|
||
### GEM_HOST_API_KEY | ||
|
||
Read to get the API key string (prefixed token with Bearer), to access the package repo. Used by `gem push`. | ||
|
||
### GEM_HOST | ||
|
||
The host URL for pushing gems to. | ||
|
||
None. | ||
## Authors | ||
|
||
* FreeAgent <[email protected]> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters