diff --git a/.gitignore b/.gitignore index 72f1ef2..2aa18d3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ node_modules/ -yarn-error.log \ No newline at end of file +yarn-error.log +.vscode +*.code-workspace diff --git a/README.md b/README.md index ac84cf3..bf6e4d2 100644 --- a/README.md +++ b/README.md @@ -26,11 +26,18 @@ jobs: run: yarn codegen - name: Build run: yarn build - - uses: gtaschuk/graph-deploy@v0.1.0 + - id: graph-deploy + uses: gtaschuk/graph-deploy@v0.1.0 with: graph_access_token: ${{secrets.GRAPH_ACCESS_TOKEN}} graph_subgraph_name: "your-subgraph-name" graph_deploy_studio: "true" graph_account: "your-github-name-or-organization" graph_config_file: "subgraph.yml" + graph_version_label: "v0.0.6" + - name: Check deploy success + run: echo "Deploy succeeded? ${{ steps.graph-deploy.outputs.success }}" + - name: Surface Studio query URL + if: ${{ steps.graph-deploy.outputs.success == 'success' && steps.graph-deploy.outputs.studio_query_url != '' }} + run: echo "Query endpoint: ${{ steps.graph-deploy.outputs.studio_query_url }}" ``` diff --git a/action.yml b/action.yml index fc2bbac..17d1851 100644 --- a/action.yml +++ b/action.yml @@ -30,6 +30,10 @@ inputs: outputs: success: description: 'The Success/Failure of the action' + value: ${{ steps.deploy.outcome }} + studio_query_url: + description: 'Graph Studio query URL for the deployed version' + value: ${{ steps.deploy.outputs.studio_query_url }} runs: using: 'composite' steps: @@ -39,10 +43,13 @@ runs: echo "$(yarn global bin)" >> $GITHUB_PATH shell: bash - id: deploy - run: | - if [ "${{inputs.graph_deploy_studio}}" = "true" ]; then - graph deploy --studio --deploy-key ${{inputs.graph_deploy_key}} ${{inputs.graph_subgraph_name}} ${{inputs.graph_config_file}} --version-label ${{inputs.graph_version_label}} - else - graph deploy --access-token ${{inputs.graph_access_token}} ${{inputs.graph_account}}/${{inputs.graph_subgraph_name}} ${{inputs.graph_config_file}} --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ - fi shell: bash + env: + GRAPH_ACCESS_TOKEN: ${{ inputs.graph_access_token }} + GRAPH_ACCOUNT: ${{ inputs.graph_account }} + GRAPH_CONFIG_FILE: ${{ inputs.graph_config_file }} + GRAPH_DEPLOY_KEY: ${{ inputs.graph_deploy_key }} + GRAPH_DEPLOY_STUDIO: ${{ inputs.graph_deploy_studio }} + GRAPH_SUBGRAPH_NAME: ${{ inputs.graph_subgraph_name }} + GRAPH_VERSION_LABEL: ${{ inputs.graph_version_label }} + run: ./scripts/graph-deploy.sh diff --git a/scripts/graph-deploy.sh b/scripts/graph-deploy.sh new file mode 100755 index 0000000..e5de5f1 --- /dev/null +++ b/scripts/graph-deploy.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +set -euo pipefail + +LOG_FILE="$(mktemp)" +trap 'rm -f "$LOG_FILE"' EXIT + +if [ "${GRAPH_DEPLOY_STUDIO}" = "true" ]; then + graph deploy \ + --studio \ + --deploy-key "${GRAPH_DEPLOY_KEY}" \ + "${GRAPH_SUBGRAPH_NAME}" \ + "${GRAPH_CONFIG_FILE}" \ + --version-label "${GRAPH_VERSION_LABEL}" | tee "$LOG_FILE" +else + graph deploy \ + --access-token "${GRAPH_ACCESS_TOKEN}" \ + "${GRAPH_ACCOUNT}/${GRAPH_SUBGRAPH_NAME}" \ + "${GRAPH_CONFIG_FILE}" \ + --ipfs https://api.thegraph.com/ipfs/ \ + --node https://api.thegraph.com/deploy/ | tee "$LOG_FILE" +fi + +if [ "${GRAPH_DEPLOY_STUDIO}" = "true" ]; then + studio_query_url="$(grep -Eo 'https://api\.studio\.thegraph\.com/query/[A-Za-z0-9_-]+/[A-Za-z0-9_-]+/[A-Za-z0-9._-]+' "$LOG_FILE" | tail -n 1 || true)" + + if [ -n "$studio_query_url" ]; then + echo "studio_query_url=$studio_query_url" >> "$GITHUB_OUTPUT" + else + echo "Unable to parse Studio query URL from deploy output. Ensure you are using the latest graph-cli." >&2 + fi +fi