2021-10-08 18:33:52 +00:00
|
|
|
name: Sync Linguist
|
2021-10-08 21:39:00 +00:00
|
|
|
on:
|
|
|
|
workflow_dispatch:
|
|
|
|
inputs:
|
|
|
|
linguist_tag:
|
|
|
|
description: 'Linguist tag override'
|
|
|
|
required: False
|
|
|
|
default: ''
|
2021-10-08 22:14:36 +00:00
|
|
|
schedule:
|
|
|
|
# Run once a day to check for new Linguist updates automatically
|
|
|
|
- cron: '0 20 * * *'
|
2021-10-08 18:33:52 +00:00
|
|
|
|
|
|
|
jobs:
|
|
|
|
sync-linguist:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
|
|
- uses: actions/setup-go@v2
|
|
|
|
- uses: actions/checkout@v2
|
2021-11-01 23:06:41 +00:00
|
|
|
- name: Find previous Linguist commit
|
|
|
|
id: previous_linguist
|
|
|
|
run: |
|
|
|
|
set -euo pipefail
|
|
|
|
IFS=$'\n\t'
|
|
|
|
commit=$(sed --quiet --regexp-extended 's/[[:space:]]+commit[[:space:]]+=[[:space:]]"([a-f0-9]{40})"/\1/p' internal/code-generator/generator/generator_test.go)
|
|
|
|
echo "::set-output name=commit::$commit"
|
2021-11-01 23:16:05 +00:00
|
|
|
echo "::set-output name=short_commit::${commit::8}"
|
2021-10-08 18:33:52 +00:00
|
|
|
- name: Create a branch
|
2021-10-08 18:55:06 +00:00
|
|
|
id: branch
|
|
|
|
run: |
|
|
|
|
set -euo pipefail
|
2021-10-08 19:20:28 +00:00
|
|
|
IFS=$'\n\t'
|
2021-10-08 18:56:56 +00:00
|
|
|
branch_name=feature/sync-linguist-$(date +%s)
|
2021-10-08 18:55:06 +00:00
|
|
|
git checkout -b $branch_name
|
|
|
|
echo "::set-output name=branch_name::$branch_name"
|
2021-10-08 18:33:52 +00:00
|
|
|
- uses: actions/checkout@v2
|
|
|
|
with:
|
|
|
|
repository: github/linguist
|
|
|
|
path: .linguist
|
|
|
|
fetch-depth: 0
|
|
|
|
- name: check out latest release
|
|
|
|
id: linguist-release
|
2021-10-08 18:42:59 +00:00
|
|
|
# the `grep -v "-"` is to exclude any pre-release versions.
|
|
|
|
# Linguist doesn't have any right now, but just in case.
|
2021-10-08 18:33:52 +00:00
|
|
|
run: |
|
2021-10-08 18:55:06 +00:00
|
|
|
set -euo pipefail
|
|
|
|
IFS=$'\n\t'
|
2021-10-08 18:33:52 +00:00
|
|
|
cd .linguist
|
2021-10-08 21:39:00 +00:00
|
|
|
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
|
|
|
|
|
2021-10-08 22:59:21 +00:00
|
|
|
if [[ -z "$latest" ]]; then
|
2021-10-08 21:10:59 +00:00
|
|
|
echo "could not determine latest Linguist version"
|
2021-10-08 19:20:28 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2021-10-08 22:59:21 +00:00
|
|
|
|
2021-10-08 18:33:52 +00:00
|
|
|
echo "::set-output name=linguist_version::$latest"
|
|
|
|
git checkout $latest
|
2021-10-08 22:59:21 +00:00
|
|
|
|
|
|
|
commit=$(git rev-parse HEAD)
|
|
|
|
if [[ -z "$commit" ]]; then
|
|
|
|
echo "could not determine latest Linguist commit"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-11-01 23:17:15 +00:00
|
|
|
echo "::set-output name=commit::$commit"
|
|
|
|
echo "::set-output name=short_commit::${commit::8}"
|
2021-10-08 22:59:21 +00:00
|
|
|
|
2021-10-08 18:33:52 +00:00
|
|
|
cd ..
|
2021-10-08 22:59:21 +00:00
|
|
|
- name: Update Linguist commit
|
|
|
|
run: |
|
2021-11-01 23:17:15 +00:00
|
|
|
sed --in-place --regexp-extended 's/(commit[[:space:]]+=[[:space:]])("[a-f0-9]{40}")/\1"${{ steps.linguist-release.outputs.commit }}"/' internal/code-generator/generator/generator_test.go
|
2021-10-08 18:33:52 +00:00
|
|
|
- name: Generate code
|
|
|
|
run: make code-generate
|
|
|
|
- name: Commit changes
|
|
|
|
id: commit
|
|
|
|
run: |
|
2021-10-08 18:55:06 +00:00
|
|
|
set -euo pipefail
|
|
|
|
IFS=$'\n\t'
|
2021-10-08 21:27:46 +00:00
|
|
|
echo "git current state:"
|
|
|
|
git status
|
|
|
|
|
2021-10-08 18:33:52 +00:00
|
|
|
if [[ -n "$(git status --porcelain)" ]]; then
|
2021-10-08 21:27:46 +00:00
|
|
|
echo "Creating Linguist update commit"
|
2021-10-08 18:33:52 +00:00
|
|
|
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 }}"
|
2021-10-08 18:55:06 +00:00
|
|
|
git push --set-upstream origin ${{ steps.branch.outputs.branch_name }}
|
2021-10-08 21:50:08 +00:00
|
|
|
echo "Changes committed. Will create PR."
|
2021-10-08 18:33:52 +00:00
|
|
|
echo "::set-output name=needs_pr::true"
|
2021-10-08 21:27:46 +00:00
|
|
|
exit 0
|
2021-10-08 18:33:52 +00:00
|
|
|
fi
|
2021-10-08 21:27:46 +00:00
|
|
|
|
|
|
|
echo "Linguist update unncessary"
|
|
|
|
echo "::set-output name=needs_pr::false"
|
2021-10-08 18:33:52 +00:00
|
|
|
- name: Create Pull Request
|
|
|
|
id: open-pr
|
|
|
|
uses: repo-sync/pull-request@v2
|
2021-10-08 21:53:47 +00:00
|
|
|
if: ${{ steps.commit.outputs.needs_pr == 'true' }}
|
2021-10-08 18:33:52 +00:00
|
|
|
with:
|
2021-10-08 22:00:53 +00:00
|
|
|
source_branch: ${{ steps.branch.outputs.branch_name }}
|
2021-10-08 22:18:02 +00:00
|
|
|
pr_title: "Update Linguist to ${{ steps.linguist-release.outputs.linguist_version }}"
|
2021-11-01 23:06:41 +00:00
|
|
|
pr_body: |
|
|
|
|
Automated Linguist update :robot:
|
|
|
|
|
2021-11-01 23:21:04 +00:00
|
|
|
This PR updates Linguist from [${{ steps.previous_linguist.outputs.short_commit }}](https://github.com/github/linguist/commit/${{ steps.previous_linguist.outputs.commit }}) to [${{ steps.linguist-release.outputs.linguist_version }}](https://github.com/github/linguist/releases/tag/${{ steps.linguist-release.outputs.linguist_version }}) ([${{ steps.linguist-release.outputs.short_commit }}](https://github.com/github/linguist/commit/${{ steps.linguist-release.outputs.commit }}))
|
2021-11-01 23:06:41 +00:00
|
|
|
|
2021-11-01 23:10:22 +00:00
|
|
|
* [Linguist release notes](https://github.com/github/linguist/releases/tag/${{ steps.linguist-release.outputs.linguist_version }})
|
2021-11-01 23:06:41 +00:00
|
|
|
* [Compare Linguist code changes](https://github.com/github/linguist/compare/${{ steps.previous_linguist.outputs.commit }}...${{ steps.linguist-release.outputs.linguist_version }})
|
2021-10-08 18:33:52 +00:00
|
|
|
destination_branch: "master"
|
|
|
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: output-url
|
2021-10-08 21:53:47 +00:00
|
|
|
if: ${{ steps.commit.outputs.needs_pr == 'true' }}
|
2021-10-08 18:33:52 +00:00
|
|
|
run: echo ${{ steps.open-pr.outputs.pr_url }}
|
|
|
|
- name: No PR Created
|
2021-10-08 21:50:08 +00:00
|
|
|
if: ${{ steps.commit.needs_pr != true }}
|
2021-10-08 18:33:52 +00:00
|
|
|
run: echo "No changes for ${{ steps.linguist-release.outputs.linguist_version }}"
|