name: Update SPDX license data on: push: paths: - .github/workflows/spdx.yml branches-ignore: - main - master schedule: - cron: "0 0 * * *" workflow_dispatch: permissions: contents: read defaults: run: shell: bash -xeuo pipefail {0} jobs: spdx: if: github.repository == 'Homebrew/brew' runs-on: ubuntu-latest steps: - name: Set up Homebrew id: set-up-homebrew uses: Homebrew/actions/setup-homebrew@main with: core: false cask: false test-bot: false - name: Configure Git user uses: Homebrew/actions/git-user-config@main with: username: BrewTestBot - name: Set up commit signing uses: Homebrew/actions/setup-commit-signing@main with: signing_key: ${{ secrets.BREWTESTBOT_SSH_SIGNING_KEY }} - name: Update SPDX license data id: update env: GITHUB_TOKEN: ${{ secrets.HOMEBREW_GITHUB_PUBLIC_REPO_TOKEN }} working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }} run: | git fetch origin BRANCH="spdx-update" echo "branch=${BRANCH}" >> "$GITHUB_OUTPUT" if git ls-remote --exit-code --heads origin "${BRANCH}" then git checkout "${BRANCH}" git checkout "Library/Homebrew/data/spdx" else git checkout --no-track -B "${BRANCH}" origin/HEAD fi if brew update-license-data then git add "Library/Homebrew/data/spdx" git commit -m "spdx: update license data." -m "Autogenerated by [a scheduled GitHub Action](https://github.com/Homebrew/brew/blob/HEAD/.github/workflows/spdx.yml)." echo "committed=true" >> "$GITHUB_OUTPUT" PULL_REQUEST_STATE="$(gh pr view --json=state | jq -r ".state" || true)" if [[ "${PULL_REQUEST_STATE}" != "OPEN" ]] then echo "pull_request=true" >> "$GITHUB_OUTPUT" fi fi - name: Push commits if: steps.update.outputs.committed == 'true' uses: Homebrew/actions/git-try-push@main with: token: ${{ secrets.HOMEBREW_GITHUB_PUBLIC_REPO_TOKEN }} directory: ${{ steps.set-up-homebrew.outputs.repository-path }} branch: ${{ steps.update.outputs.branch }} force: true origin_branch: "HEAD" - name: Open a pull request if: steps.update.outputs.pull_request == 'true' run: gh pr create --fill env: GITHUB_TOKEN: ${{ secrets.HOMEBREW_GITHUB_PUBLIC_REPO_TOKEN }} working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }} issue: needs: spdx if: always() && github.event_name == 'schedule' runs-on: ubuntu-latest env: RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} permissions: # To create or update issues issues: write steps: - name: Open, update, or close SPDX issue uses: Homebrew/actions/create-or-update-issue@main with: title: Failed to update SPDX license data body: > The SPDX license data workflow [failed](${{ env.RUN_URL }}). No SPDX license data was updated. labels: bug update-existing: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped') }} close-existing: ${{ needs.spdx.result == 'success' }} close-from-author: github-actions[bot] close-comment: > The SPDX license data workflow [succeeded](${{ env.RUN_URL }}). Closing this issue.