-
Notifications
You must be signed in to change notification settings - Fork 191
100 lines (87 loc) · 3.38 KB
/
add_new_versions.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
name: Add New Docker Versions
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * 3"
permissions:
contents: write
id-token: write
pull-requests: write
jobs:
generate_and_raise_pr:
runs-on: ubuntu-latest
steps:
- name: Read App Secrets
uses: rancher-eio/read-vault-secrets@main
with:
secrets: |
secret/data/github/repo/${{ github.repository }}/github/app-credentials appId | APP_ID ;
secret/data/github/repo/${{ github.repository }}/github/app-credentials privateKey | PRIVATE_KEY
- name: Create App Token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ env.APP_ID }}
private-key: ${{ env.PRIVATE_KEY }}
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ steps.app-token.outputs.token }}
- uses: actions/setup-python@v5
with:
python-version: '3.10'
cache: 'pip'
- name: Pip
working-directory: ./workflow_scripts
run: pip install -r requirements.txt
- name: Check if new versions available
id: check-versions
run: |
python -u workflow_scripts/check-for-new-versions.py
env:
EXCLUDED_VERSIONS: "v20.10.x,v23.0.x,v25.0.x,v26.1.x"
- name: check if the PR exist
if: ${{ env.PR_TITLE != '' }}
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
PR_TITLE: ${{env.PR_TITLE}}
run: |
EXISTING_PR=$(gh pr list --limit 1500 --json title,url | jq --arg title "${PR_TITLE}" -r '.[] | select(.title==$title) | .url')
if [ -n "${EXISTING_PR}" ]; then
echo "pr_exist=true" >> $GITHUB_ENV
echo "Pull request already exists: ${EXISTING_PR}" >> $GITHUB_STEP_SUMMARY
else
echo "pr_exist=false" >> $GITHUB_ENV
fi
- name: generate files for new docker version
if: ${{ env.pr_exist == 'false' && env.PR_TITLE != '' }}
env:
NEW_VERSIONS: ${{ env.NEW_VERSIONS }}
run: |
python -u workflow_scripts/gen-new-version-files.py
- name: Create branch, commit and push
if: ${{ env.pr_exist == 'false' && env.PR_TITLE != '' }}
id: branch
env:
NEW_VERSIONS: ${{ env.NEW_VERSIONS }}
run: |
BRANCH="gha-add-tag-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
echo "branch=${BRANCH}" >> $GITHUB_OUTPUT
git config user.name github-actions
git config user.email [email protected]
git checkout -b "$BRANCH"
git add .
git commit -m "added docker ${NEW_VERSIONS}"
git push origin "$BRANCH"
- name: Create Pull Request
if: ${{ env.pr_exist == 'false' && env.PR_TITLE != '' }}
id: cpr
env:
SOURCE_BRANCH: ${{ steps.branch.outputs.branch }}
GH_TOKEN: ${{ steps.app-token.outputs.token }}
PR_TITLE: ${{env.PR_TITLE}}
PR_BODY: autogenerated PR to add docker ${{env.NEW_VERSIONS}}
run: |
PR_TITLE=$(echo "$PR_TITLE" | cut -c -256)
CREATED_PR=$(gh pr create --title "${PR_TITLE}" --body "${PR_BODY}" --label "status/auto-created" --base "${GITHUB_REF_NAME}" --head "${SOURCE_BRANCH}")
echo "Created pull request: ${CREATED_PR}" >> $GITHUB_STEP_SUMMARY