|
| 1 | +on: |
| 2 | + push: |
| 3 | + branches: |
| 4 | + - main |
| 5 | + workflow_dispatch: |
| 6 | + |
| 7 | +name: Validate, generate and publish registry |
| 8 | + |
| 9 | +jobs: |
| 10 | + upload-registry: |
| 11 | + name: Upload to Cloudflare Pages |
| 12 | + runs-on: ubuntu-latest |
| 13 | + permissions: |
| 14 | + contents: 'write' |
| 15 | + steps: |
| 16 | + - name: Checkout Repository |
| 17 | + uses: actions/checkout@v4 |
| 18 | + with: |
| 19 | + fetch-depth: 0 |
| 20 | + ssh-key: ${{ secrets.DEPLOY_KEY }} |
| 21 | + |
| 22 | + - name: Setup Bun |
| 23 | + uses: oven-sh/setup-bun@v1 |
| 24 | + with: |
| 25 | + bun-version: latest |
| 26 | + |
| 27 | + - name: Install dependencies |
| 28 | + run: bun install --no-save |
| 29 | + |
| 30 | + - name: Validate schema |
| 31 | + run: bun validate:schema |
| 32 | + |
| 33 | + - name: Generate registry types |
| 34 | + run: bun generate:types |
| 35 | + |
| 36 | + - name: Validate logic |
| 37 | + run: | |
| 38 | + if [ -z "${{ env.THEGRAPH_STUDIO_KEY }}" ]; then |
| 39 | + echo "Error: secrets.THEGRAPH_STUDIO_KEY is not set - can't validate networks" |
| 40 | + exit 1 |
| 41 | + fi |
| 42 | + bun validate:networks |
| 43 | +
|
| 44 | + - name: Generate registry |
| 45 | + run: bun generate:public |
| 46 | + |
| 47 | + - name: Format |
| 48 | + run: bun format |
| 49 | + |
| 50 | + - name: Get version |
| 51 | + id: get_version |
| 52 | + run: | |
| 53 | + VERSION=$(jq -r '.version' package.json) |
| 54 | + echo "REGISTRY_VERSION=${VERSION}" >> $GITHUB_ENV |
| 55 | +
|
| 56 | + - name: Check if tag exists |
| 57 | + id: check_tag |
| 58 | + run: | |
| 59 | + if git fetch --tags && git tag -l | grep -q "v${{ env.REGISTRY_VERSION }}"; then |
| 60 | + echo "Error: Registry v${{ env.REGISTRY_VERSION }} already exists. Bump up the version in package.json to publish" |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | +
|
| 64 | + - name: Publish |
| 65 | + uses: cloudflare/wrangler-action@v3 |
| 66 | + with: |
| 67 | + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 68 | + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
| 69 | + command: pages deploy public --project-name=graphregistry |
| 70 | + |
| 71 | + - name: Get commit log |
| 72 | + run: | |
| 73 | + PREV_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") |
| 74 | + if [ -z "$PREV_TAG" ]; then |
| 75 | + CHANGELOG=$(git log --pretty=format:"- %s (@%an) [%h](https://github.com/$GITHUB_REPOSITORY/commit/%H)" --no-merges) |
| 76 | + else |
| 77 | + CHANGELOG=$(git log --pretty=format:"- %s (@%an) [%h](https://github.com/$GITHUB_REPOSITORY/commit/%H)" --no-merges ${PREV_TAG}..HEAD) |
| 78 | + fi |
| 79 | + echo "CHANGELOG<<EOF" >> $GITHUB_ENV |
| 80 | + echo "$CHANGELOG" >> $GITHUB_ENV |
| 81 | + echo "EOF" >> $GITHUB_ENV |
| 82 | +
|
| 83 | + - name: Commit and Push Changes |
| 84 | + run: | |
| 85 | + git config --global user.name 'github-actions[bot]' |
| 86 | + git config --global user.email 'github-actions[bot]@users.noreply.github.com' |
| 87 | +
|
| 88 | + git add . |
| 89 | + git commit -m "generate registry v${{ env.REGISTRY_VERSION }} [no ci]" || echo "No changes to commit" |
| 90 | + git push |
| 91 | +
|
| 92 | + - name: Create tag |
| 93 | + run: | |
| 94 | + git tag "v${{ env.REGISTRY_VERSION }}" |
| 95 | + git push origin "v${{ env.REGISTRY_VERSION }}" |
| 96 | +
|
| 97 | + IFS='.' read -r MAJOR MINOR PATCH <<< "${{ env.REGISTRY_VERSION }}" |
| 98 | + echo "MAJOR=$MAJOR" >> $GITHUB_ENV |
| 99 | + echo "MINOR=$MINOR" >> $GITHUB_ENV |
| 100 | + echo "PATCH=$PATCH" >> $GITHUB_ENV |
| 101 | +
|
| 102 | + - name: Create GitHub release |
| 103 | + uses: actions/create-release@v1 |
| 104 | + env: |
| 105 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 106 | + with: |
| 107 | + tag_name: "v${{ env.REGISTRY_VERSION }}" |
| 108 | + release_name: "v${{ env.REGISTRY_VERSION }}" |
| 109 | + body: | |
| 110 | + ### Networks Registry v${{ env.REGISTRY_VERSION }} |
| 111 | + - ${{ env.REGISTRY_ROOT_URL }}/TheGraphNetworksRegistry.json |
| 112 | + - ${{ env.REGISTRY_ROOT_URL }}/TheGraphNetworksRegistry_v${{ env.MAJOR }}_x_x.json |
| 113 | + - ${{ env.REGISTRY_ROOT_URL }}/TheGraphNetworksRegistry_v${{ env.MAJOR }}_${{ env.MINOR }}_x.json |
| 114 | + - ${{ env.REGISTRY_ROOT_URL }}/TheGraphNetworksRegistry_v${{ env.MAJOR }}_${{ env.MINOR }}_${{ env.PATCH }}.json |
| 115 | +
|
| 116 | + ### Schema v${{ env.MAJOR }}.${{ env.MINOR }} |
| 117 | + - ${{ env.REGISTRY_ROOT_URL }}/TheGraphNetworksRegistrySchema_v${{ env.MAJOR }}_${{ env.MINOR }}.json |
| 118 | +
|
| 119 | + ### Changes |
| 120 | + ${{ env.CHANGELOG }} |
| 121 | +
|
| 122 | + env: |
| 123 | + THEGRAPH_STUDIO_KEY: ${{ secrets.THEGRAPH_STUDIO_KEY }} |
| 124 | + REGISTRY_ROOT_URL: "https://graphregistry.pages.dev" |
0 commit comments