Skip to content

Update README

Update README #43

Workflow file for this run

name: Update README
on: workflow_dispatch
permissions:
contents: write
pull-requests: write
jobs:
update-readme:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Update README file
run: |
tagstmpfile=$(mktemp)
readmetmpfile=$(mktemp)
gh api graphql -F owner='rancher' -F name='rke' -f query='query($name: String!, $owner: String!) {repository(owner: $owner, name: $name) {releases(first: 100) {nodes { tagName }}}}' |jq -r .data.repository.releases[] > $tagstmpfile
for rke_major_minor in 1.4 1.3 1.2; do
latest=$(jq -r 'first(.[] | select(.tagName | startswith("v'"${rke_major_minor}"'")) | select(.tagName | contains("rc") | not) | .tagName)' $tagstmpfile)
echo "* v${rke_major_minor}" >> $readmetmpfile
echo " * ${latest} - Read the full release [notes](https://github.com/rancher/rke/releases/tag/${latest})." >> $readmetmpfile
done
sed -e '/## Latest Release/r '"$readmetmpfile"'' -e 's/CURRENTYEAR/'"$(date +%Y)"'/g' README-template.md > README.md
env:
GH_TOKEN: ${{ github.token }}
- name: Check for repository changes
run: |
if git diff --name-only --exit-code; then
echo "No changes found in repository after updating README"
echo "changes_exist=false" >> $GITHUB_ENV
else
echo "Changes found in repository after updating README:"
git diff --name-only
echo "changes_exist=true" >> $GITHUB_ENV
fi
- name: Create branch, commit and push
if: ${{ env.changes_exist == 'true' }}
id: branch
run: |
BRANCH="githubaction-update-readme-$(date +%Y-%m-%d-%H-%M-%S)"
echo "::set-output name=branch::$BRANCH"
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git checkout -b "$BRANCH"
git commit -a -m "update README with latest"
git push origin "$BRANCH"
- name: Create Pull Request
if: ${{ env.changes_exist == 'true' }}
id: cpr
env:
SOURCE_BRANCH: ${{ steps.branch.outputs.branch }}
uses: actions/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
let body = 'Auto-generated by GitHub Actions'
const { data: pr } = await github.rest.pulls.create({
title: `[${{ github.ref_name }}] update README with latest`,
body: body,
owner: context.repo.owner,
repo: context.repo.repo,
base: "${{ github.ref_name }}",
head: `${ process.env.SOURCE_BRANCH }`
});
await github.rest.issues.addLabels({
...context.repo,
issue_number: pr.number,
labels: ["status/auto-created"],
});
console.log('Created new pull request');
return pr.html_url;
- name: Check outputs
if: ${{ env.changes_exist == 'true' }}
run: |
echo "Pull Request URL - ${{ steps.cpr.outputs.result }}"