Last active
June 29, 2021 15:31
-
-
Save ybiquitous/9a43fb94de2b3a632a391599df0b6af6 to your computer and use it in GitHub Desktop.
Create pull request to bump git version via GitHub Actions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Bump git | |
on: | |
schedule: | |
- cron: "0 0 * * 1-5" | |
workflow_dispatch: | |
env: | |
target_file: Dockerfile | |
jobs: | |
bump-git: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- uses: octokit/[email protected] | |
id: latest_tag | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
query: | | |
query { | |
repository(owner: "git", name: "git") { | |
refs(refPrefix: "refs/tags/", first: 1, orderBy: {field: TAG_COMMIT_DATE, direction: DESC}) { | |
edges { | |
node { | |
name | |
} | |
} | |
} | |
} | |
} | |
- name: Set variables | |
id: vars | |
run: | | |
latest_version=$(echo '${{ fromJson(steps.latest_tag.outputs.data).repository.refs.edges[0].node.name }}' | sed -E 's/^v(.+)/\1/') | |
echo ::set-output name=latest_version::${latest_version} | |
echo ::set-output name=current_version::$(grep -o -E 'GIT_VERSION=.+$' '${{ env.target_file }}' | sed -E 's/GIT_VERSION=//') | |
if [[ ${latest_version} =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
echo ::set-output name=valid_version::true | |
else | |
echo "Skip bumping to ${latest_version}" | |
fi | |
- name: Update file | |
run: sed -i -E 's/GIT_VERSION=.+$/GIT_VERSION=${{ steps.vars.outputs.latest_version }}/' '${{ env.target_file }}' | |
if: ${{ steps.vars.outputs.valid_version == 'true' }} | |
- uses: peter-evans/create-pull-request@v3 | |
if: ${{ steps.vars.outputs.valid_version == 'true' }} | |
with: | |
title: Bump git from ${{ steps.vars.outputs.current_version }} to ${{ steps.vars.outputs.latest_version }} | |
body: | | |
- https://github.com/git/git/blob/v${{ steps.vars.outputs.latest_version }}/Documentation/RelNotes/${{ steps.vars.outputs.latest_version }}.txt | |
- https://github.com/git/git/compare/v${{ steps.vars.outputs.current_version }}...v${{ steps.vars.outputs.latest_version }} | |
branch: bump-git-${{ steps.vars.outputs.latest_version }} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See also