Skip to content

Sync Fork with Upstream #175

Sync Fork with Upstream

Sync Fork with Upstream #175

Workflow file for this run

name: Sync Fork with Upstream
on:
schedule:
- cron: '0 0 * * *' # Runs daily at midnight UTC
workflow_dispatch: # Allows manual triggering
push:
branches:
- main
pull_request:
branches:
- main
permissions:
contents: write
pull-requests: write
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout fork
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.PAT_SYNC }}
- name: Set up Git
run: |
git config user.name "GitHub Action"
git config user.email "[email protected]"
- name: Add upstream remote and fetch
run: |
git remote add upstream https://github.com/observeinc/terraform-azure-collection.git || true
git fetch upstream --tags
- name: Sync main branch
run: |
git checkout main
git merge upstream/main --allow-unrelated-histories --no-edit || (echo "Merge conflicts detected. Please resolve manually."; exit 1)
git push origin main
- name: Push tags
run: |
git push origin --tags
- name: Install GitHub CLI
uses: sersoft-gmbh/setup-gh-cli-action@v2
with:
version: stable
- name: Sync releases
env:
GH_TOKEN: ${{ secrets.PAT_SYNC }}
run: |
echo "Fetching releases from upstream..."
upstream_repo="observeinc/terraform-azure-collection"
fork_repo="${{ github.repository }}"
# Get upstream releases
gh api -H "Accept: application/vnd.github+json" /repos/$upstream_repo/releases | jq -c '.[]' > releases.json
while IFS= read -r release; do
tag_name=$(echo "$release" | jq -r .tag_name)
title=$(echo "$release" | jq -r .name)
body=$(echo "$release" | jq -r .body)
draft=$(echo "$release" | jq -r .draft)
prerelease=$(echo "$release" | jq -r .prerelease)
# Skip drafts
if [ "$draft" = "true" ]; then
echo "Skipping draft release: $tag_name"
continue
fi
# Check if release already exists
if gh release view "$tag_name" --repo "$fork_repo" > /dev/null 2>&1; then
echo "Release $tag_name already exists in fork, skipping."
else
echo "Creating release $tag_name in fork..."
flags=""
if [ "$prerelease" = "true" ]; then
flags="--prerelease"
fi
gh release create "$tag_name" --repo "$fork_repo" --title "$title" --notes "$body" $flags
fi
done < releases.json