spdx.yml 2.3 KB
Newer Older
1
name: Update SPDX license data
2
on:
3
  push:
4
5
    paths:
      - .github/workflows/spdx.yml
6
7
    branches-ignore:
      - master
8
  schedule:
Mike McQuaid's avatar
Mike McQuaid 已提交
9
    - cron: "0 0 * * *"
10
11
jobs:
  spdx:
12
    if: github.repository == 'Homebrew/brew'
13
14
    runs-on: ubuntu-latest
    steps:
15
16
17
      - name: Set up Homebrew
        id: set-up-homebrew
        uses: Homebrew/actions/setup-homebrew@master
18

19
      - name: Configure Git user
20
21
22
23
        uses: Homebrew/actions/git-user-config@master
        with:
          username: BrewTestBot

24
25
26
27
28
      - name: Set up commit signing
        uses: Homebrew/actions/setup-commit-signing@master
        with:
          signing_key: ${{ secrets.BREWTESTBOT_GPG_SIGNING_SUBKEY }}

29
30
      - name: Update SPDX license data
        id: update
31
32
33
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          HOMEBREW_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
34
          GPG_PASSPHRASE: ${{ secrets.BREWTESTBOT_GPG_SIGNING_SUBKEY_PASSPHRASE }}
35
        run: |
36
37
38
39
40
41
42
43
44
45
46
47
          git fetch origin

          BRANCH="spdx-update"
          echo "::set-output name=branch::${BRANCH}"

          if git ls-remote --exit-code --heads origin "$BRANCH"; then
            git checkout "$BRANCH"
            git reset origin/master
          else
            git checkout -B "$BRANCH" origin/master
            BRANCH_EXISTS="1"
          fi
48
49

          if brew update-license-data --fail-if-not-changed; then
Mike McQuaid's avatar
Mike McQuaid 已提交
50
51
52
            git add "$GITHUB_WORKSPACE/Library/Homebrew/data/spdx"
            git commit -m "spdx: update license data." -m "Autogenerated by [a scheduled GitHub Action](https://github.com/Homebrew/brew/blob/master/.github/workflows/spdx.yml)."
            echo "::set-output name=committed::true"
53
54
55
            if [ -n "$BRANCH_EXISTS" ]; then
              echo "::set-output name=pull_request::true"
            fi
56
          fi
57
58
59
60
61
62

      - name: Push commits
        if: steps.update.outputs.committed == 'true'
        uses: Homebrew/actions/git-try-push@master
        with:
          token: ${{ secrets.HOMEBREW_GITHUB_API_TOKEN }}
63
          branch: ${{ steps.update.outputs.branch }}
Mike McQuaid's avatar
Mike McQuaid 已提交
64
          force: true
65
66

      - name: Open a pull request
67
        if: steps.update.outputs.pull_request == 'true'
Mike McQuaid's avatar
Mike McQuaid 已提交
68
        run: hub pull-request --no-edit
69
70
        env:
          GITHUB_TOKEN: ${{ secrets.HOMEBREW_GITHUB_API_TOKEN }}