Sync latest upstream release to main #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Sync latest upstream release to main | |
| on: | |
| schedule: | |
| - cron: "2 20 * * *" | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| concurrency: | |
| group: open-connector-release-sync | |
| cancel-in-progress: false | |
| env: | |
| D1_DATABASE_ID: 3919bbda-4559-4f97-a755-7e1f8b330577 | |
| R2_BUCKET_NAME: open-connector-transit-files | |
| INITIAL_RELEASE: v1.0.3 | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check out this production branch | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Resolve the latest stable upstream release | |
| id: release | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| tag="$(gh api repos/oomol-lab/open-connector/releases/latest --jq '.tag_name')" | |
| case "$tag" in | |
| v*) ;; | |
| *) echo "Unexpected upstream release tag: $tag" >&2; exit 1 ;; | |
| esac | |
| echo "tag=$tag" >> "$GITHUB_OUTPUT" | |
| - name: Check whether this release is already tracked | |
| id: state | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| TAG: ${{ steps.release.outputs.tag }} | |
| run: | | |
| if [ "$TAG" = "$INITIAL_RELEASE" ]; then | |
| echo "skip=true" >> "$GITHUB_OUTPUT" | |
| echo "The currently deployed Worker is newer than the initial tracked release $TAG." | |
| elif gh api "repos/$GITHUB_REPOSITORY/git/ref/tags/open-connector-synced-$TAG" >/dev/null 2>&1; then | |
| echo "skip=true" >> "$GITHUB_OUTPUT" | |
| echo "$TAG is already synced to main." | |
| else | |
| echo "skip=false" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Fetch the immutable upstream release | |
| if: steps.state.outputs.skip != 'true' | |
| env: | |
| TAG: ${{ steps.release.outputs.tag }} | |
| run: | | |
| cp .github/workflows/deploy-upstream-release.yml "$RUNNER_TEMP/deploy-upstream-release.yml" | |
| git remote add upstream https://github.com/oomol-lab/open-connector.git | |
| git fetch --depth=1 upstream "refs/tags/$TAG:refs/tags/$TAG" | |
| git read-tree --reset -u "$TAG" | |
| - name: Set up Node.js | |
| if: steps.state.outputs.skip != 'true' | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "24" | |
| cache: npm | |
| - name: Validate the upstream release | |
| if: steps.state.outputs.skip != 'true' | |
| run: | | |
| npm ci | |
| npm run lint | |
| npm run format | |
| npm run build | |
| npm test | |
| - name: Prepare Worker assets and production configuration | |
| if: steps.state.outputs.skip != 'true' | |
| run: | | |
| npm run generate:catalog | |
| npm run build:web | |
| node scripts/copy-catalog-assets.ts | |
| cp wrangler.example.jsonc wrangler.jsonc | |
| sed -i "s/<your-d1-database-id>/$D1_DATABASE_ID/" wrangler.jsonc | |
| sed -i "s/<your-bucket-name>/$R2_BUCKET_NAME/" wrangler.jsonc | |
| mkdir -p .github/workflows | |
| cp "$RUNNER_TEMP/deploy-upstream-release.yml" .github/workflows/deploy-upstream-release.yml | |
| - name: Update main and record the synced release | |
| if: steps.state.outputs.skip != 'true' | |
| env: | |
| TAG: ${{ steps.release.outputs.tag }} | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add -A | |
| git commit -m "chore: sync upstream release $TAG" | |
| git tag -a "open-connector-synced-$TAG" -m "Synced upstream release $TAG" | |
| git push origin HEAD:main | |
| git push origin "open-connector-synced-$TAG" |