diff --git a/.github/workflows/_docs.yaml b/.github/workflows/_docs.yaml index abc9695..3902ebb 100644 --- a/.github/workflows/_docs.yaml +++ b/.github/workflows/_docs.yaml @@ -29,6 +29,7 @@ jobs: run: > markdownlint-cli2 "**/*.{md,markdown}" + "#**/CHANGELOG.md" build: needs: lint diff --git a/.github/workflows/_release_please.yaml b/.github/workflows/_release_please.yaml new file mode 100644 index 0000000..6622eb6 --- /dev/null +++ b/.github/workflows/_release_please.yaml @@ -0,0 +1,37 @@ +name: Release Please + +on: + workflow_call: + secrets: + GRAPH_FEDERATOR: + required: true + +jobs: + release_please: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + id-token: write + steps: + - name: Checkout source + uses: actions/checkout@v4.2.2 + with: + fetch-depth: 0 + + - name: Create GitHub App Token + id: app-token + uses: actions/create-github-app-token@v1.11.0 + with: + app-id: 1010045 + private-key: ${{ secrets.GRAPH_FEDERATOR }} + repositories: graph-federation + + - name: Release Please + id: release + uses: googleapis/release-please-action@v4.1.3 + with: + token: ${{ steps.app-token.outputs.token }} + config-file: release-please-config.json + manifest-file: .release-please-manifest.json + fork: false diff --git a/.github/workflows/_supergraph_publish.yaml b/.github/workflows/_supergraph_publish.yaml index 5a2dd2d..6e56187 100644 --- a/.github/workflows/_supergraph_publish.yaml +++ b/.github/workflows/_supergraph_publish.yaml @@ -15,39 +15,46 @@ jobs: with: fetch-depth: 0 + - name: Setup Node + uses: actions/setup-node@v4.1.0 + + - name: Install release-please & simple-git + run: npm install release-please simple-git + + - name: Generate Chart Version + id: version + uses: actions/github-script@v7.0.1 + with: + result-encoding: string + script: | + const supergraph_tag = require('.github/workflows/supergraph_tag.js'); + const token = "${{ github.token }}"; + return await supergraph_tag({github, context, token}) + - name: Setup Helm + if: steps.version.outputs.result != '' uses: azure/setup-helm@v4.2.0 - name: Download Schema Artifact + if: steps.version.outputs.result != '' uses: actions/download-artifact@v4.1.8 with: name: supergraph.graphql path: charts/supergraph - - name: Generate Chart Version - id: version - run: | - if LATEST_TAG=$(git describe --tags --abbrev=0); then - COMMITS_SINCE=$(git rev-list $LATEST_TAG..HEAD --count) - else - LATEST_TAG="0.0.0" - COMMITS_SINCE=$(git rev-list HEAD --count) - fi - VERSION=$([ "$COMMITS_SINCE" == 0 ] && echo "$LATEST_TAG" || echo "$LATEST_TAG+$COMMITS_SINCE" ) - echo "Using Version: $VERSION" - echo "version=$VERSION" >> $GITHUB_OUTPUT - - name: Package Chart - run: helm package charts/supergraph --version "${{ steps.version.outputs.version }}" + if: steps.version.outputs.result != '' + run: helm package charts/supergraph --version ${{ steps.version.outputs.result }} - name: Generate Image Name + if: steps.version.outputs.result != '' run: | IMAGE_REPOSITORY="oci://ghcr.io/$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]' | tr '[_]' '[\-]')" echo "Using Image Name: $IMAGE_REPOSITORY" echo "IMAGE_REPOSITORY=$IMAGE_REPOSITORY" >> $GITHUB_ENV - name: Log in to GitHub Docker Registry - if: github.event_name == 'push' && ( startsWith(github.ref, 'refs/tags') || startsWith(github.ref, 'refs/heads/main') ) + if: steps.version.outputs.result != '' && github.event_name == 'push' && ( startsWith(github.ref, 'refs/tags') || startsWith(github.ref, 'refs/heads/main') ) uses: docker/login-action@v3.3.0 with: registry: ghcr.io @@ -55,5 +62,5 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Publish Chart - if: github.event_name == 'push' && ( startsWith(github.ref, 'refs/tags') || startsWith(github.ref, 'refs/heads/main') ) + if: steps.version.outputs.result != '' && github.event_name == 'push' && ( startsWith(github.ref, 'refs/tags') || startsWith(github.ref, 'refs/heads/main') ) run: helm push $(ls supergraph-*.tgz) ${{ env.IMAGE_REPOSITORY }} diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b512eb1..42cbf90 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -10,6 +10,16 @@ jobs: if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository uses: ./.github/workflows/_lint_commits.yaml + release_please: + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + uses: ./.github/workflows/_release_please.yaml + permissions: + contents: write + pull-requests: write + id-token: write + secrets: + GRAPH_FEDERATOR: ${{ secrets.GRAPH_FEDERATOR }} + helm_lint: # Deduplicate jobs from pull requests and branch pushes within the same repo. if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository @@ -24,6 +34,7 @@ jobs: # Deduplicate jobs from pull requests and branch pushes within the same repo. if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository needs: + - release_please - helm_lint - supergraph_generate uses: ./.github/workflows/_supergraph_publish.yaml diff --git a/.github/workflows/supergraph_tag.js b/.github/workflows/supergraph_tag.js new file mode 100644 index 0000000..876ca8d --- /dev/null +++ b/.github/workflows/supergraph_tag.js @@ -0,0 +1,40 @@ +const releasePlease = require('release-please'); +const simpleGit = require('simple-git'); + +module.exports = async ({github, context, token}) => { + const ghRelease = await releasePlease.GitHub.create({ + owner: context.repo.owner, + repo: context.repo.repo, + token: token, + }); + + const manifest = await releasePlease.Manifest.fromManifest( + ghRelease, + ghRelease.repository.defaultBranch, + 'release-please-config.json', + '.release-please-manifest.json', + {} + ); + + const pullRequests = await manifest.buildPullRequests(); + const pullRequest = pullRequests.find((pullRequest) => pullRequest.updates.some((update) => update.path === 'charts/supergraph/Chart.yaml')); + console.log(`Supergraph Pull Request: ${JSON.stringify(pullRequest)}`); + + const git = simpleGit(); + const lastTag = await git.raw('describe', '--tags', '--match', 'supergraph@v*', 'HEAD').catch((err) => undefined); + console.log(`Last Tag: ${JSON.stringify(lastTag)}`); + const commitsSince = lastTag ? await git.raw('rev-list', `${lastTag}..HEAD`, '--count') : await git.raw('rev-list', '--count', '--all'); + console.log(`Commits Since: ${commitsSince}`); + + let rcVersion = ''; + if (pullRequest !== undefined) { + + const releaseData = pullRequest.body.releaseData.find((release) => release.component === 'supergraph-schema'); + rcVersion = commitsSince !== 0 ? `${releaseData.version.major}.${releaseData.version.minor}.${releaseData.version.patch}-rc${commitsSince}` : `${releaseData.version.major}.${releaseData.version.minor}.${releaseData.version.patch}`; + console.log(`Release Candidate Version: ${rcVersion}`); + } else if (lastTag !== undefined && commitsSince === 0) { + rcVersion = lastTag.split("@v").pop(); + }; + + return rcVersion +} diff --git a/.release-please-manifest.json b/.release-please-manifest.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/.release-please-manifest.json @@ -0,0 +1 @@ +{} diff --git a/release-please-config.json b/release-please-config.json new file mode 100644 index 0000000..095b3ed --- /dev/null +++ b/release-please-config.json @@ -0,0 +1,53 @@ +{ + "$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json", + "bootstrap-sha": "ee1cb51e2177608be9e291f6bde17ca5d867016e", + "include-component-in-tag": true, + "include-v-in-tag": true, + "tag-separator": "@", + "separate-pull-requests": true, + "bump-minor-pre-major": true, + "bump-patch-for-minor-pre-major": true, + "packages": { + "charts/apps": { + "release-type": "helm", + "release-as": "0.2.2" + }, + "charts/graph": { + "release-type": "helm", + "release-as": "0.11.1" + }, + "charts/monitoring": { + "release-type": "helm", + "release-as": "0.2.0" + }, + "charts/supergraph": { + "release-type": "helm", + "component": "supergraph" + }, + "schema": { + "package-name": "supergraph-schema", + "release-type": "simple", + "component": "supergraph-schema" + }, + "workflows/compose": { + "package-name": "compose", + "release-type": "simple", + "release-as": "0.1.0" + }, + "workflows/update": { + "package-name": "update", + "release-type": "simple", + "release-as": "0.1.0" + } + }, + "plugins": [ + { + "type": "linked-versions", + "groupName": "supergraph", + "components": [ + "supergraph", + "supergraph-schema" + ] + } + ] +}