forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
82 lines (79 loc) · 4.04 KB
/
update-readme.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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: Get chart index.yaml files
run: |
wget https://github.com/mikefarah/yq/releases/download/v4.25.1/yq_linux_amd64 -O /usr/bin/yq && chmod +x /usr/bin/yq
wget -O latest.index.yaml https://releases.rancher.com/server-charts/latest/index.yaml
wget -O stable.index.yaml https://releases.rancher.com/server-charts/stable/index.yaml
- name: Update README file
run: |
tmpfile=$(mktemp)
latest26=$(yq '.entries.rancher[].appVersion | select(test("^v2.6") and select(. != "*-rc*"))' 'latest.index.yaml' | head -1)
stable26=$(yq '.entries.rancher[].appVersion | select(test("^v2.6") and select(. != "*-rc*"))' 'stable.index.yaml' | head -1)
latest25=$(yq '.entries.rancher[].appVersion | select(test("^v2.5") and select(. != "*-rc*"))' 'latest.index.yaml' | head -1)
stable25=$(yq '.entries.rancher[].appVersion | select(test("^v2.5") and select(. != "*-rc*"))' 'stable.index.yaml' | head -1)
echo "* v2.6" > $tmpfile
echo " * Latest - ${latest26} - \`rancher/rancher:${latest26}\` / \`rancher/rancher:latest\` - Read the full release [notes](https://github.com/rancher/rancher/releases/tag/${latest26})." >> $tmpfile
echo " * Stable - ${stable26} - \`rancher/rancher:${stable26}\` / \`rancher/rancher:stable\` - Read the full release [notes](https://github.com/rancher/rancher/releases/tag/${stable26})." >> $tmpfile
echo "* v2.5" >> $tmpfile
echo " * Latest - ${latest25} - \`rancher/rancher:${latest25}\` - Read the full release [notes](https://github.com/rancher/rancher/releases/tag/${latest25})." >> $tmpfile
echo " * Stable - ${stable25} - \`rancher/rancher:${stable25}\` - Read the full release [notes](https://github.com/rancher/rancher/releases/tag/${stable25})." >> $tmpfile
sed -e '/## Latest Release/r '"$tmpfile"'' -e 's/CURRENTYEAR/'"$(date +%Y)"'/g' README-template.md > README.md
- 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/stable"
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/stable`,
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 }}"