name: Sync Linguist on: workflow_dispatch: inputs: linguist_tag: description: 'Linguist tag override' required: False default: '' jobs: sync-linguist: runs-on: ubuntu-latest steps: - uses: actions/setup-go@v2 - uses: actions/checkout@v2 - name: Create a branch id: branch run: | set -euo pipefail IFS=$'\n\t' branch_name=feature/sync-linguist-$(date +%s) git checkout -b $branch_name echo "::set-output name=branch_name::$branch_name" - uses: actions/checkout@v2 with: repository: github/linguist path: .linguist fetch-depth: 0 - name: check out latest release id: linguist-release # the `grep -v "-"` is to exclude any pre-release versions. # Linguist doesn't have any right now, but just in case. run: | set -euo pipefail IFS=$'\n\t' cd .linguist if [[ -n "${{ github.event.inputs.linguist_tag }}" ]]; then echo "Using tag override '${{ github.event.inputs.linguist_tag }}'" latest="${{ github.event.inputs.linguist_tag }}" else latest=$(git tag --list | \ grep -v "-" | \ sort --version-sort --reverse | \ head -1) fi if [[ -z $latest ]]; then echo "could not determine latest Linguist version" exit 1 fi echo "::set-output name=linguist_version::$latest" git checkout $latest cd .. - name: Generate code run: make code-generate - name: Commit changes id: commit run: | set -euo pipefail IFS=$'\n\t' echo "git current state:" git status if [[ -n "$(git status --porcelain)" ]]; then echo "Creating Linguist update commit" git config user.name github-actions git config user.email github-actions@github.com git add . git commit -m "Updated Linguist to ${{ steps.linguist-release.outputs.linguist_version }}" git push --set-upstream origin ${{ steps.branch.outputs.branch_name }} echo "Changes committed. Will create PR." echo "::set-output name=needs_pr::true" exit 0 fi echo "Linguist update unncessary" echo "::set-output name=needs_pr::false" - name: Create Pull Request id: open-pr uses: repo-sync/pull-request@v2 if: ${{ steps.commit.outputs.needs_pr == 'true' }} with: destination_branch: "master" github_token: ${{ secrets.GITHUB_TOKEN }} - name: output-url if: ${{ steps.commit.outputs.needs_pr == 'true' }} run: echo ${{ steps.open-pr.outputs.pr_url }} - name: No PR Created if: ${{ steps.commit.needs_pr != true }} run: echo "No changes for ${{ steps.linguist-release.outputs.linguist_version }}"