generated from actions/container-action
-
Notifications
You must be signed in to change notification settings - Fork 26
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 #3 from dawidd6/rewrite-in-ruby
Rewrite in Ruby
- Loading branch information
Showing
6 changed files
with
134 additions
and
200 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 |
---|---|---|
@@ -1,26 +1,28 @@ | ||
name: Test Action | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
on: push | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
formula: | ||
- dawidd6/test/test-formula-url | ||
- dawidd6/test/test-formula-git-revision | ||
include: | ||
- formula: dawidd6/test/test-formula-url | ||
tag: v0.1.12 | ||
- formula: dawidd6/test/test-formula-git-revision | ||
tag: v0.3.3 | ||
revision: c43abd765cf51c06bbcaa5479dc49aab1396989f | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
- name: Test | ||
uses: ./ | ||
with: | ||
token: ${{secrets.TOKEN}} | ||
formula: dawidd6/homebrew-test/test-formula-url | ||
url: https://github.com/dawidd6/actions-updater/archive/v0.1.12.tar.gz | ||
- name: Test | ||
uses: ./ | ||
with: | ||
token: ${{secrets.TOKEN}} | ||
formula: dawidd6/homebrew-test/test-formula-git-revision | ||
tag: v0.3.3 | ||
revision: c43abd765cf51c06bbcaa5479dc49aab1396989f | ||
formula: ${{matrix.formula}} | ||
tag: ${{matrix.tag}} | ||
revision: ${{matrix.revision}} |
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 |
---|---|---|
@@ -1,5 +1,10 @@ | ||
FROM homebrew/brew | ||
|
||
COPY *.sh / | ||
ENV HOMEBREW_NO_ENV_FILTERING=1 | ||
ENV HOMEBREW_NO_AUTO_UPDATE=1 | ||
ENV HOMEBREW_NO_ANALYTICS=1 | ||
ENV HOMEBREW_COLOR=1 | ||
|
||
ENTRYPOINT ["/main.sh"] | ||
COPY main.rb / | ||
|
||
ENTRYPOINT ["brew", "ruby", "/main.rb"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# frozen_string_literal: true | ||
|
||
module Homebrew | ||
module_function | ||
|
||
def brew(*args) | ||
puts "[command]brew #{args.join(' ')}" | ||
return if ENV['DEBUG'] | ||
|
||
safe_system('brew', *args) | ||
end | ||
|
||
def git(*args) | ||
puts "[command]git #{args.join(' ')}" | ||
return if ENV['DEBUG'] | ||
|
||
safe_system('git', *args) | ||
end | ||
|
||
# Get inputs | ||
token = ENV['INPUT_TOKEN'] | ||
formula = ENV['INPUT_FORMULA'] | ||
tag = ENV['INPUT_TAG'] | ||
revision = ENV['INPUT_REVISION'] | ||
force = ENV['INPUT_FORCE'] | ||
|
||
# Die if required inputs are not provided | ||
odie 'TOKEN is required' if token.blank? | ||
odie 'FORMULA is required' if formula.blank? | ||
odie 'TAG is required' if tag.blank? | ||
|
||
# Set needed HOMEBREW environment variables | ||
ENV['HOMEBREW_GITHUB_API_TOKEN'] = token | ||
|
||
# Get user details | ||
actor = ENV['GITHUB_ACTOR'] | ||
user = GitHub.open_api "#{GitHub::API_URL}/users/#{actor}" | ||
user_name = user['name'] || actor | ||
user_email = user['email'] || ( | ||
# https://help.github.com/en/github/setting-up-and-managing-your-github-user-account/setting-your-commit-email-address | ||
user_created_at = Date.parse user['created_at'] | ||
plus_after_date = Date.parse '2017-07-18' | ||
need_plus_email = (user_created_at - plus_after_date).positive? | ||
user_email = "#{actor}@users.noreply.github.com" | ||
user_email = "#{user['id']}+#{user_email}" if need_plus_email | ||
user_email | ||
) | ||
|
||
# Tell git who you are | ||
git 'config', '--global', 'user.name', user_name | ||
git 'config', '--global', 'user.email', user_email | ||
|
||
# Update Homebrew | ||
brew 'update-reset' | ||
|
||
# Tap if desired | ||
tap = formula[%r{^(.+/.+)/.+$}, 1] | ||
brew 'tap', tap if tap | ||
|
||
# Get info about formula | ||
stable = Formula[formula].stable | ||
is_git = stable.downloader.is_a? GitDownloadStrategy | ||
|
||
# Prepare tag and url | ||
tag = tag.delete_prefix 'refs/tags/' | ||
url = stable.url.gsub stable.version, Version.parse(tag) | ||
|
||
# Finally bump the formula | ||
brew 'bump-formula-pr', | ||
'--no-audit', | ||
'--no-browse', | ||
'--message=[`action-homebrew-bump-formula`](https://github.com/dawidd6/action-homebrew-bump-formula)', | ||
*("--url=#{url}" unless is_git), | ||
*("--tag=#{tag}" if is_git), | ||
*("--revision=#{revision}" if is_git), | ||
*('--force' unless force.blank?), | ||
formula | ||
end |