-
Notifications
You must be signed in to change notification settings - Fork 0
102 lines (87 loc) · 3.67 KB
/
create-linked-release.yml
File metadata and controls
102 lines (87 loc) · 3.67 KB
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
101
102
name: Create Linked Tag from Upstream Repo
on:
schedule:
# Runs 4 times a day (every 6 hours)
- cron: '0 */6 * * *'
# A simple manual trigger for testing.
workflow_dispatch:
permissions:
# 'contents: write' is required to push tags to the repository.
contents: write
jobs:
sync-tag:
runs-on: ubuntu-latest
steps:
- name: Get latest stable release from public upstream repo
id: get_release_b
uses: ophiosdev/github-action-latest-release@master
with:
# Reads the UPSTREAM_REPO variable from your repository settings.
# This variable is REQUIRED for the workflow to function.
repository: ${{ vars.UPSTREAM_REPO }}
includes: ${{ vars.VERSION_REGEX || '^v?[0-9]+\.[0-9]+\.[0-9]+$' }}
token: ${{ secrets.GITHUB_TOKEN }}
- name: Validate Release Tag Format
id: validate_tag
env:
VERSION_REGEX: ${{ vars.VERSION_REGEX || '^v?[0-9]+\.[0-9]+\.[0-9]+$' }}
run: |
TAG_NAME="${{ steps.get_release_b.outputs.release }}"
echo "Validating release tag format for latest release from upstream repository: $TAG_NAME"
if [[ -z "$TAG_NAME" ]]; then
echo "No valid release found from upstream repository. Exiting."
echo "is_valid=false" >> "$GITHUB_OUTPUT"
exit 0
fi
if [[ "$TAG_NAME" =~ $VERSION_REGEX ]]; then
echo "Tag '$TAG_NAME' matches the required format."
echo "is_valid=true" >> "$GITHUB_OUTPUT"
# Extract matched portion (Bash stores full match in BASH_REMATCH[0])
new_version="${BASH_REMATCH[0]}"
echo "Extracted version: $new_version"
echo "new_version=$new_version" >> "$GITHUB_OUTPUT"
else
echo "Tag '$TAG_NAME' does not match the required format. Ignoring."
echo "is_valid=false" >> "$GITHUB_OUTPUT"
fi
- name: Generate GitHub App token
id: app_token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ secrets.WORKFLOW_APP_ID }}
private-key: ${{ secrets.WORKFLOW_APP_PRIVATE_KEY }}
- name: Checkout repository code
# We need to check out the code to be able to check for existing tags and push new ones.
if: steps.validate_tag.outputs.is_valid == 'true'
uses: actions/checkout@v5
with:
fetch-depth: 0
fetch-tags: true
token: ${{ steps.app_token.outputs.token }}
- name: Check if tag already exists locally
id: check_tag
if: steps.validate_tag.outputs.is_valid == 'true'
env:
RELEASE_TAG: ${{ steps.validate_tag.outputs.new_version }}
run: |
RELEASE_TAG="v${RELEASE_TAG#v}" # Ensure the tag starts with 'v'
if git tag --list | grep -q "^${RELEASE_TAG}$"; then
echo "Tag '$RELEASE_TAG' already exists. No action needed."
echo "create_tag=false" >> "$GITHUB_OUTPUT"
else
echo "New valid tag '$RELEASE_TAG' detected!"
echo "create_tag=true" >> "$GITHUB_OUTPUT"
fi
- name: Create and push new tag
id: create_and_push
# This step only runs if the tag is valid AND new.
if: steps.check_tag.outputs.create_tag == 'true'
env:
RELEASE_TAG: ${{ steps.validate_tag.outputs.new_version }}
run: |
RELEASE_TAG="v${RELEASE_TAG#v}" # Ensure the tag starts with 'v'
echo "Creating tag: $RELEASE_TAG"
git tag "$RELEASE_TAG"
echo "Pushing tag to remote..."
git push origin "$RELEASE_TAG"
echo "Successfully created and pushed tag '$RELEASE_TAG'."