Skip to content

Commit 712f828

Browse files
committed
feat: added workflow to constantly pull releases on gemini-cli upstream repo
1 parent 87e77ea commit 712f828

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
name: Create Linked Release from Upstream Repo
2+
3+
on:
4+
schedule:
5+
# Runs 4 times a day (every 6 hours)
6+
- cron: '0 */6 * * *'
7+
8+
workflow_dispatch:
9+
10+
permissions:
11+
contents: write
12+
13+
jobs:
14+
sync-and-link-release:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Get latest stable release from public upstream repo
19+
id: get_release_b
20+
uses: pozetroninc/github-action-get-latest-release@master
21+
with:
22+
# Reads the UPSTREAM_REPO variable from your repository settings.
23+
# This variable is REQUIRED for the workflow to function.
24+
repository: ${{ vars.UPSTREAM_REPO }}
25+
excludes: prerelease, draft
26+
27+
- name: Validate Release Tag Format
28+
id: validate_tag
29+
env:
30+
# Use the repo variable if it exists, otherwise use the hardcoded default regex.
31+
VERSION_REGEX: ${{ vars.VERSION_REGEX || '^v?[0-9]+\.[0-9]+\.[0-9]+$' }}
32+
run: |
33+
TAG_NAME="${{ steps.get_release_b.outputs.tag }}"
34+
if [[ -z "$TAG_NAME" ]]; then
35+
echo "No valid release found from upstream repository. Exiting."
36+
echo "is_valid=false" >> "$GITHUB_OUTPUT"
37+
exit 0
38+
fi
39+
40+
if [[ "$TAG_NAME" =~ $VERSION_REGEX ]]; then
41+
echo "Tag '$TAG_NAME' matches the required format."
42+
echo "is_valid=true" >> "$GITHUB_OUTPUT"
43+
else
44+
echo "Tag '$TAG_NAME' does not match the required format. Ignoring."
45+
echo "is_valid=false" >> "$GITHUB_OUTPUT"
46+
fi
47+
48+
- name: Check if release tag already exists in this repository
49+
id: check_release_a
50+
if: steps.validate_tag.outputs.is_valid == 'true'
51+
env:
52+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53+
RELEASE_TAG: ${{ steps.get_release_b.outputs.tag }}
54+
run: |
55+
if gh release view "$RELEASE_TAG" >/dev/null 2>&1; then
56+
echo "Release tag '$RELEASE_TAG' already exists. No action needed."
57+
echo "new_release_detected=false" >> "$GITHUB_OUTPUT"
58+
else
59+
echo "New valid release tag '$RELEASE_TAG' detected!"
60+
echo "new_release_detected=true" >> "$GITHUB_OUTPUT"
61+
fi
62+
63+
- name: Create new linked release in this repository
64+
if: steps.check_release_a.outputs.new_release_detected == 'true'
65+
env:
66+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
UPSTREAM_REPO: ${{ vars.UPSTREAM_REPO }}
68+
# Use the repo variable for the template if it exists, otherwise use the default.
69+
# Note: We use \n for newlines to keep it a valid one-line expression.
70+
NOTES_TEMPLATE: ${{ vars.RELEASE_NOTE_TEMPLATE || 'This release corresponds to the upstream release in the **{{RepositoryName}}** repository.\n\n**Original Release:** {{URL}}' }}
71+
RELEASE_TAG: ${{ steps.get_release_b.outputs.tag }}
72+
RELEASE_NAME: ${{ steps.get_release_b.outputs.name }}
73+
RELEASE_URL: ${{ steps.get_release_b.outputs.html_url }}
74+
run: |
75+
REPO_NAME_ONLY=${UPSTREAM_REPO#*/}
76+
NOTES_WITH_REPO_NAME="${NOTES_TEMPLATE//'{{RepositoryName}}'/$REPO_NAME_ONLY}"
77+
FINAL_NOTES="${NOTES_WITH_REPO_NAME//'{{URL}}'/$RELEASE_URL}"
78+
79+
gh release create "$RELEASE_TAG" \
80+
--title "$RELEASE_NAME" \
81+
--notes "$FINAL_NOTES"
82+
83+
echo "Successfully created release '$RELEASE_NAME' with tag '$RELEASE_TAG'."

0 commit comments

Comments
 (0)