diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000000..f95ac9fc08 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,38 @@ +name: GitHub Actions CI +on: + push: + branches: master + pull_request: [] +jobs: + tests: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macOS-latest] + steps: + - name: Set up Git repository + uses: actions/checkout@master + + - name: Set up Homebrew + run: | + HOMEBREW_REPOSITORY="$(brew --repo)" + mv "$HOMEBREW_REPOSITORY/Library/Taps" "$PWD/Library" + sudo rm -rf "$HOMEBREW_REPOSITORY" + sudo ln -s "$PWD" "$HOMEBREW_REPOSITORY" + brew update-reset Library/Taps/homebrew/homebrew-core + if: matrix.os == 'macOS-latest' + + - name: Build Docker image + run: docker-compose -f Dockerfile.yml build sut + if: matrix.os == 'ubuntu-latest' + + - name: Run brew test-bot + run: | + if [ "$RUNNER_OS" = "Linux" ]; then + docker-compose -f Dockerfile.yml run --rm -v $GITHUB_WORKSPACE:/tmp/test-bot sut + else + brew test-bot + fi + env: + HOMEBREW_COVERALLS_REPO_TOKEN: ${{ secrets.HOMEBREW_COVERALLS_REPO_TOKEN }} + HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Dockerfile.yml b/Dockerfile.yml index e672123b73..b147f7c74b 100644 --- a/Dockerfile.yml +++ b/Dockerfile.yml @@ -4,16 +4,24 @@ sut: - sh - -xc - | - sudo -E -u linuxbrew /home/linuxbrew/.linuxbrew/bin/brew test-bot + /home/linuxbrew/.linuxbrew/bin/brew test-bot status=$$? - cp brew-test-bot.xml /tmp/test-bot/ exit $$status environment: - - HOME=/home/linuxbrew + # GitHub Actions + - GITHUB_ACTIONS + - GITHUB_BASE_REF + - GITHUB_EVENT_NAME + - GITHUB_REF + - GITHUB_REPOSITORY + - GITHUB_SHA + - HEAD_GITHUB_REF + # Azure Pipelines - BUILD_REASON - BUILD_REPOSITORY_URI - BUILD_SOURCEVERSION - - HOMEBREW_GITHUB_API_TOKEN - SYSTEM_PULLREQUEST_PULLREQUESTNUMBER - SYSTEM_PULLREQUEST_TARGETBRANCH - TF_BUILD + # GitHub API + - HOMEBREW_GITHUB_API_TOKEN diff --git a/Library/Homebrew/dev-cmd/update-test.rb b/Library/Homebrew/dev-cmd/update-test.rb index 99b2ebd03f..fc5a7350f3 100644 --- a/Library/Homebrew/dev-cmd/update-test.rb +++ b/Library/Homebrew/dev-cmd/update-test.rb @@ -46,19 +46,24 @@ module Homebrew Utils.popen_read("git", "rev-list", "-n1", "--before=#{date}", "origin/master").chomp elsif args.to_tag? tags = Utils.popen_read("git", "tag", "--list", "--sort=-version:refname") - previous_tag = tags.lines.second - previous_tag ||= begin - if (HOMEBREW_REPOSITORY/".git/shallow").exist? + if tags.blank? + tags = if (HOMEBREW_REPOSITORY/".git/shallow").exist? safe_system "git", "fetch", "--tags", "--depth=1" - tags = Utils.popen_read("git", "tag", "--list", "--sort=-version:refname") + Utils.popen_read("git", "tag", "--list", "--sort=-version:refname") elsif OS.linux? - tags = Utils.popen_read("git tag --list | sort -rV") + Utils.popen_read("git tag --list | sort -rV") end - tags.lines.second end + current_tag, previous_tag, = tags.lines + current_tag = current_tag.to_s.chomp + odie "Could not find current tag in:\n#{tags}" if current_tag.empty? + # ^0 ensures this points to the commit rather than the tag object. + end_commit = "#{current_tag}^0" + previous_tag = previous_tag.to_s.chomp odie "Could not find previous tag in:\n#{tags}" if previous_tag.empty? - previous_tag + # ^0 ensures this points to the commit rather than the tag object. + "#{previous_tag}^0" else Utils.popen_read("git", "rev-parse", "origin/master").chomp end @@ -67,8 +72,13 @@ module Homebrew start_commit = Utils.popen_read("git", "rev-parse", start_commit).chomp odie "Could not find start commit!" if start_commit.empty? - end_commit = Utils.popen_read("git", "rev-parse", "HEAD").chomp + end_commit ||= "HEAD" + end_commit = Utils.popen_read("git", "rev-parse", end_commit).chomp odie "Could not find end commit!" if end_commit.empty? + + if Utils.popen_read("git", "branch", "--list", "master").blank? + safe_system "git", "branch", "master", "origin/master" + end end puts "Start commit: #{start_commit}" @@ -80,10 +90,12 @@ module Homebrew oh1 "Setup test environment..." # copy Homebrew installation - safe_system "git", "clone", "--local", "#{HOMEBREW_REPOSITORY}/.git", "." + safe_system "git", "clone", "#{HOMEBREW_REPOSITORY}/.git", ".", + "--local", "--branch", "master", "--single-branch" # set git origin to another copy - safe_system "git", "clone", "--local", "--bare", "#{HOMEBREW_REPOSITORY}/.git", "remote.git" + safe_system "git", "clone", "#{HOMEBREW_REPOSITORY}/.git", "remote.git", + "--local", "--bare", "--branch", "master", "--single-branch" safe_system "git", "config", "remote.origin.url", "#{curdir}/remote.git" # force push origin to end_commit @@ -100,7 +112,7 @@ module Homebrew oh1 "Running brew update..." safe_system "brew", "update", "--verbose" actual_end_commit = Utils.popen_read("git", "rev-parse", branch).chomp - if start_commit != end_commit && start_commit == actual_end_commit + if actual_end_commit != end_commit raise <<~EOS brew update didn't update #{branch}! Start commit: #{start_commit} @@ -110,6 +122,6 @@ module Homebrew end end ensure - FileUtils.rm_r "update-test" unless args.keep_tmp? + FileUtils.rm_rf "update-test" unless args.keep_tmp? end end diff --git a/Library/Homebrew/extend/os/mac/diagnostic.rb b/Library/Homebrew/extend/os/mac/diagnostic.rb index 09b2754932..5d5e2eec9b 100644 --- a/Library/Homebrew/extend/os/mac/diagnostic.rb +++ b/Library/Homebrew/extend/os/mac/diagnostic.rb @@ -72,7 +72,7 @@ module Homebrew # `brew test-bot` runs `brew doctor` in the CI for the Homebrew/brew # repository. This only needs to support whatever CI providers # Homebrew/brew is currently using. - return if ENV["HOMEBREW_AZURE_PIPELINES"] || ENV["HOMEBREW_GITHUB_ACTIONS"] + return if ENV["HOMEBREW_GITHUB_ACTIONS"] message = <<~EOS Your Xcode (#{MacOS::Xcode.version}) is outdated. @@ -99,7 +99,7 @@ module Homebrew # `brew test-bot` runs `brew doctor` in the CI for the Homebrew/brew # repository. This only needs to support whatever CI providers # Homebrew/brew is currently using. - return if ENV["HOMEBREW_AZURE_PIPELINES"] || ENV["HOMEBREW_GITHUB_ACTIONS"] + return if ENV["HOMEBREW_GITHUB_ACTIONS"] <<~EOS A newer Command Line Tools release is available. diff --git a/Library/Homebrew/test/spec_helper.rb b/Library/Homebrew/test/spec_helper.rb index 8388cfc9e3..1ded62cb16 100644 --- a/Library/Homebrew/test/spec_helper.rb +++ b/Library/Homebrew/test/spec_helper.rb @@ -27,11 +27,6 @@ if ENV["HOMEBREW_TESTS_COVERAGE"] ENV["COVERALLS_REPO_TOKEN"] = ENV["HOMEBREW_COVERALLS_REPO_TOKEN"] end - if ENV["HOMEBREW_AZURE_PIPELINES"] - require "simplecov-cobertura" - formatters << SimpleCov::Formatter::CoberturaFormatter - end - SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new(formatters) end diff --git a/azure-pipelines.yml b/azure-pipelines.yml deleted file mode 100644 index 30bbdd14f3..0000000000 --- a/azure-pipelines.yml +++ /dev/null @@ -1,52 +0,0 @@ -jobs: -- job: macOS - pool: - vmImage: macOS-10.14 - steps: - - bash: | - set -e - sudo xcode-select --switch /Applications/Xcode_10.2.app/Contents/Developer - HOMEBREW_REPOSITORY="$(brew --repo)" - mv "$HOMEBREW_REPOSITORY/Library/Taps" "$PWD/Library" - sudo rm -rf "$HOMEBREW_REPOSITORY" - sudo ln -s "$PWD" "$HOMEBREW_REPOSITORY" - brew update-reset Library/Taps/homebrew/homebrew-core - brew test-bot - displayName: Run brew test-bot - env: - HOMEBREW_GITHUB_API_TOKEN: $(github.publicApiToken) - HOMEBREW_COVERALLS_REPO_TOKEN: $(coveralls.homebrewBrewApiToken) - - - task: PublishTestResults@2 - displayName: Publish test-bot test results - condition: succeededOrFailed() - inputs: - testRunner: JUnit - testResultsFiles: brew-test-bot.xml - - - task: PublishCodeCoverageResults@1 - displayName: Publish brew tests code coverage - inputs: - codeCoverageTool: Cobertura - summaryFileLocation: $(Build.SourcesDirectory)/coverage/coverage.xml - reportDirectory: $(Build.SourcesDirectory)/coverage - failIfCoverageEmpty: true - -- job: Linux - pool: - vmImage: ubuntu-16.04 - steps: - - bash: docker-compose -f Dockerfile.yml build sut - displayName: Build Docker image - - - bash: docker-compose -f Dockerfile.yml run --rm -v $(Build.ArtifactStagingDirectory):/tmp/test-bot sut - displayName: Run brew test-bot - env: - HOMEBREW_GITHUB_API_TOKEN: $(github.publicApiToken) - - - task: PublishTestResults@2 - displayName: Publish test-bot test results - condition: succeededOrFailed() - inputs: - testRunner: JUnit - testResultsFiles: $(Build.ArtifactStagingDirectory)/brew-test-bot.xml diff --git a/bin/brew b/bin/brew index edf2dded7f..77bcb906f7 100755 --- a/bin/brew +++ b/bin/brew @@ -65,8 +65,9 @@ do export "$VAR_NEW"="${!VAR}" done -# Set CI variable for Azure Pipelines, Jenkins. -if [[ -n "$TF_BUILD" || -n "$JENKINS_HOME" ]] +# Set CI variable for GitHub Actions, Azure Pipelines, Jenkins +# (Set by default on Circle and Travis CI) +if [[ -n "$GITHUB_ACTIONS" || -n "$TF_BUILD" || -n "$JENKINS_HOME" ]] then export CI="1" fi