From 496c511ce3a46b03e5726858271dd22d4cdc12d1 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Fri, 3 Mar 2023 18:53:59 -0600 Subject: [PATCH 01/57] chore: try using built image --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index f7217e247..2f3154189 100644 --- a/action.yml +++ b/action.yml @@ -10,4 +10,4 @@ inputs: required: true runs: using: docker - image: Dockerfile + image: 'docker://ghcr.io/readmeio/rdme:next' From 3caf8007652fa1e8e49e239e43ba720844c3a0ea Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Fri, 3 Mar 2023 18:57:51 -0600 Subject: [PATCH 02/57] chore: temporarily try pointing to previous commit --- .github/workflows/ci.yml | 4 ++-- .github/workflows/docs.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4c1ea763a..b73de0915 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,12 +52,12 @@ jobs: repository: readmeio/oas-examples - name: Run `openapi:validate` command - uses: ./rdme-repo/ + uses: readmeio/rdme@496c511ce3a46b03e5726858271dd22d4cdc12d1 with: rdme: openapi:validate oas-examples-repo/3.1/json/petstore.json # Docs: https://rdme-test.readme.io - name: Run `openapi` command - uses: ./rdme-repo/ + uses: readmeio/rdme@496c511ce3a46b03e5726858271dd22d4cdc12d1 with: rdme: openapi oas-examples-repo/3.1/json/petstore.json --key=${{ secrets.RDME_TEST_PROJECT_API_KEY }} --id=${{ secrets.RDME_TEST_PROJECT_API_SETTING }} diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index e0d105643..8d99f07b1 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -48,7 +48,7 @@ jobs: # First we're going to perform a dry run of syncing process. # We do this on every push to ensure that an actual sync will work properly - name: Sync docs to ReadMe (dry run) - uses: ./ + uses: readmeio/rdme@496c511ce3a46b03e5726858271dd22d4cdc12d1 with: rdme: docs ./documentation --key=${{ secrets.README_DEVELOPERS_API_KEY }} --version=${{ vars.README_DEVELOPERS_MAIN_VERSION }} --dryRun From 99dc555ee16d4869e0e91aab09532637a7c3af7b Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Fri, 3 Mar 2023 18:59:43 -0600 Subject: [PATCH 03/57] chore: try pointing to v8 ... just to see how much slower it is --- .github/workflows/ci.yml | 4 ++-- .github/workflows/docs.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b73de0915..33c937dc9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,12 +52,12 @@ jobs: repository: readmeio/oas-examples - name: Run `openapi:validate` command - uses: readmeio/rdme@496c511ce3a46b03e5726858271dd22d4cdc12d1 + uses: readmeio/rdme@v8 with: rdme: openapi:validate oas-examples-repo/3.1/json/petstore.json # Docs: https://rdme-test.readme.io - name: Run `openapi` command - uses: readmeio/rdme@496c511ce3a46b03e5726858271dd22d4cdc12d1 + uses: readmeio/rdme@v8 with: rdme: openapi oas-examples-repo/3.1/json/petstore.json --key=${{ secrets.RDME_TEST_PROJECT_API_KEY }} --id=${{ secrets.RDME_TEST_PROJECT_API_SETTING }} diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 8d99f07b1..dc3d03a0e 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -48,7 +48,7 @@ jobs: # First we're going to perform a dry run of syncing process. # We do this on every push to ensure that an actual sync will work properly - name: Sync docs to ReadMe (dry run) - uses: readmeio/rdme@496c511ce3a46b03e5726858271dd22d4cdc12d1 + uses: readmeio/rdme@v8 with: rdme: docs ./documentation --key=${{ secrets.README_DEVELOPERS_API_KEY }} --version=${{ vars.README_DEVELOPERS_MAIN_VERSION }} --dryRun From b5b83fb85d56b36056837891afaf0f413ab8a395 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 6 Mar 2023 17:57:02 -0600 Subject: [PATCH 04/57] chore: try running this --- .github/workflows/release.yml | 58 +++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b3b703947..2779a4a7a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,29 +1,55 @@ name: Release on: push: - branches: - - main - - next + # branches: + # - main + # - next + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} jobs: release: runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: - uses: actions/checkout@v3 with: fetch-depth: 0 token: ${{ secrets.RELEASE_GH_TOKEN }} - - uses: actions/setup-node@v3 + + - name: Log in to the Container registry + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 with: - node-version: 16 - cache: 'npm' - - name: Install dependencies and build TS - run: npm ci && npm run build - - name: Install semantic-release and friends - run: npm i --no-save semantic-release@19 @semantic-release/changelog@6 @semantic-release/exec@6 @semantic-release/git@10 - - name: Run semantic-release workflow - env: - GH_TOKEN: ${{ secrets.RELEASE_GH_TOKEN }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - run: npx semantic-release + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + github-token: ${{ secrets.GITHUB_TOKEN }} + + - name: log metadata + run: echo $DOCKER_METADATA_OUTPUT_JSON + + # - uses: actions/setup-node@v3 + # with: + # node-version: 16 + # cache: 'npm' + # - name: Install dependencies and build TS + # run: npm ci && npm run build + # - name: Install semantic-release and friends + # run: npm i --no-save semantic-release@19 @semantic-release/changelog@6 @semantic-release/exec@6 @semantic-release/git@10 + # - name: Run semantic-release workflow + # env: + # GH_TOKEN: ${{ secrets.RELEASE_GH_TOKEN }} + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + # run: npx semantic-release From 89135339c79903921b8f9051daf3bd87361e6cfa Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 6 Mar 2023 18:02:56 -0600 Subject: [PATCH 05/57] fix: whoops update refs --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2779a4a7a..603090beb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,7 +23,7 @@ jobs: token: ${{ secrets.RELEASE_GH_TOKEN }} - name: Log in to the Container registry - uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + uses: docker/login-action@v2 with: registry: ${{ env.REGISTRY }} username: ${{ github.actor }} @@ -31,7 +31,7 @@ jobs: - name: Extract metadata (tags, labels) for Docker id: meta - uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + uses: docker/metadata-action@v4 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} github-token: ${{ secrets.GITHUB_TOKEN }} From 3dc156ba1fd697b120eea35487bc13f5d09afaf4 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 6 Mar 2023 18:10:23 -0600 Subject: [PATCH 06/57] chore: log this --- .github/workflows/release.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 603090beb..ddb54bc63 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -38,6 +38,8 @@ jobs: - name: log metadata run: echo $DOCKER_METADATA_OUTPUT_JSON + - name: log actor + run: echo ${{ github.actor }} # - uses: actions/setup-node@v3 # with: From 1c33428f5cf70d32d695da17d7ed89c46273e62b Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 6 Mar 2023 18:34:51 -0600 Subject: [PATCH 07/57] chore: try building --- .github/workflows/release.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ddb54bc63..275b45759 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -29,6 +29,9 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Build (but do NOT push) + uses: docker/build-push-action@v4 + - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@v4 From d71018ecbe60c2120258fa373ce54c28e6705dbd Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 6 Mar 2023 18:43:45 -0600 Subject: [PATCH 08/57] chore: try adding tag info --- .github/workflows/release.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 275b45759..681e83ad8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -36,8 +36,11 @@ jobs: id: meta uses: docker/metadata-action@v4 with: - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} github-token: ${{ secrets.GITHUB_TOKEN }} + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=semver,pattern={{version}},value=8.6.0-next.13 + type=ref,event=branch - name: log metadata run: echo $DOCKER_METADATA_OUTPUT_JSON From 7d74cc1b0bf457bed62f8deae88a3f228f2355f9 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 6 Mar 2023 19:18:14 -0600 Subject: [PATCH 09/57] feat: some versioning mess-around ... to see if the image builds with everything properly --- .github/workflows/docs.yml | 2 +- .github/workflows/release.yml | 16 +++++++++++----- bin/set-version-output.js | 6 ++++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index dc3d03a0e..b67ed5f3c 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -36,7 +36,7 @@ jobs: uses: jacobtomlinson/gha-find-replace@v3 with: find: 'RDME_VERSION' - replace: ${{ steps.rdme-version.outputs.RDME_VERSION }} + replace: ${{ steps.rdme-version.outputs.RDME_LATEST_MAJOR_VERSION }} regex: false include: documentation/* diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 681e83ad8..4444f1d33 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -29,8 +29,9 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Build (but do NOT push) - uses: docker/build-push-action@v4 + - name: Get current package version + id: rdme-version + run: ./bin/set-version-output.js - name: Extract metadata (tags, labels) for Docker id: meta @@ -39,13 +40,18 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | - type=semver,pattern={{version}},value=8.6.0-next.13 + type=semver,pattern={{version}},value=${{ steps.rdme-version.outputs.RDME_PKG_VERSION }} type=ref,event=branch + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} - name: log metadata run: echo $DOCKER_METADATA_OUTPUT_JSON - - name: log actor - run: echo ${{ github.actor }} + + - name: Build (but do NOT push) + uses: docker/build-push-action@v4 + with: + labels: ${{ steps.meta.outputs.labels }} + tags: ${{ steps.meta.outputs.tags }} # - uses: actions/setup-node@v3 # with: diff --git a/bin/set-version-output.js b/bin/set-version-output.js index f4d4a34de..2bd5c19f1 100755 --- a/bin/set-version-output.js +++ b/bin/set-version-output.js @@ -1,16 +1,18 @@ #! /usr/bin/env node const core = require('@actions/core'); -const { getNodeVersion, getMajorPkgVersion } = require('../dist/src/lib/getPkgVersion'); +const { getMajorPkgVersion, getNodeVersion, getPkgVersion } = require('../dist/src/lib/getPkgVersion'); /** * Sets output parameters for GitHub Actions workflow so we can do * a find-and-replace in our docs prior to syncing them to ReadMe + * and also to tag our Docker images properly * Docs: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter */ async function setOutputs() { - core.setOutput('RDME_VERSION', `v${await getMajorPkgVersion('latest')}`); core.setOutput('NODE_VERSION', getNodeVersion()); + core.setOutput('RDME_LATEST_MAJOR_VERSION', `v${await getMajorPkgVersion('latest')}`); + core.setOutput('RDME_PKG_VERSION', await getPkgVersion()); } setOutputs(); From e6b50927e4901c7742c211af3b7ff6474f6b726e Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 6 Mar 2023 19:20:14 -0600 Subject: [PATCH 10/57] revert: restore dry run pointers --- .github/workflows/ci.yml | 4 ++-- .github/workflows/docs.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 33c937dc9..4c1ea763a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -52,12 +52,12 @@ jobs: repository: readmeio/oas-examples - name: Run `openapi:validate` command - uses: readmeio/rdme@v8 + uses: ./rdme-repo/ with: rdme: openapi:validate oas-examples-repo/3.1/json/petstore.json # Docs: https://rdme-test.readme.io - name: Run `openapi` command - uses: readmeio/rdme@v8 + uses: ./rdme-repo/ with: rdme: openapi oas-examples-repo/3.1/json/petstore.json --key=${{ secrets.RDME_TEST_PROJECT_API_KEY }} --id=${{ secrets.RDME_TEST_PROJECT_API_SETTING }} diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index b67ed5f3c..e07ce11da 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -48,7 +48,7 @@ jobs: # First we're going to perform a dry run of syncing process. # We do this on every push to ensure that an actual sync will work properly - name: Sync docs to ReadMe (dry run) - uses: readmeio/rdme@v8 + uses: ./ with: rdme: docs ./documentation --key=${{ secrets.README_DEVELOPERS_API_KEY }} --version=${{ vars.README_DEVELOPERS_MAIN_VERSION }} --dryRun From 714eaf286d45371da4fd3b31d3806326a44de2c2 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 6 Mar 2023 19:21:24 -0600 Subject: [PATCH 11/57] fix: bring back install step, move stuff to the bottom --- .github/workflows/release.yml | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4444f1d33..a22a80114 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,6 +22,23 @@ jobs: fetch-depth: 0 token: ${{ secrets.RELEASE_GH_TOKEN }} + - uses: actions/setup-node@v3 + with: + node-version: 16 + cache: 'npm' + + - name: Install dependencies and build TS + run: npm ci && npm run build + + # - name: Install semantic-release and friends + # run: npm i --no-save semantic-release@19 @semantic-release/changelog@6 @semantic-release/exec@6 @semantic-release/git@10 + # - name: Run semantic-release workflow + # env: + # GH_TOKEN: ${{ secrets.RELEASE_GH_TOKEN }} + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + # run: npx semantic-release + - name: Log in to the Container registry uses: docker/login-action@v2 with: @@ -52,18 +69,3 @@ jobs: with: labels: ${{ steps.meta.outputs.labels }} tags: ${{ steps.meta.outputs.tags }} - - # - uses: actions/setup-node@v3 - # with: - # node-version: 16 - # cache: 'npm' - # - name: Install dependencies and build TS - # run: npm ci && npm run build - # - name: Install semantic-release and friends - # run: npm i --no-save semantic-release@19 @semantic-release/changelog@6 @semantic-release/exec@6 @semantic-release/git@10 - # - name: Run semantic-release workflow - # env: - # GH_TOKEN: ${{ secrets.RELEASE_GH_TOKEN }} - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - # run: npx semantic-release From 22b2e9bd4e55c35a3bedf81c2469526970ffc91c Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 6 Mar 2023 19:22:41 -0600 Subject: [PATCH 12/57] chore: remove useless logging step --- .github/workflows/release.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a22a80114..ef3c24be7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -61,9 +61,6 @@ jobs: type=ref,event=branch type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} - - name: log metadata - run: echo $DOCKER_METADATA_OUTPUT_JSON - - name: Build (but do NOT push) uses: docker/build-push-action@v4 with: From 1a952bdc514eea0a02f7f48de4ad6b8a58b07819 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 6 Mar 2023 19:25:57 -0600 Subject: [PATCH 13/57] chore: what happens if i do this? --- .github/workflows/release.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ef3c24be7..87ebbe410 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -64,5 +64,6 @@ jobs: - name: Build (but do NOT push) uses: docker/build-push-action@v4 with: + github-token: ${{ secrets.GITHUB_TOKEN }} labels: ${{ steps.meta.outputs.labels }} tags: ${{ steps.meta.outputs.tags }} From 125ddec4604c72c1d66e29364c846ee5fb7aa0cf Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 6 Mar 2023 19:53:05 -0600 Subject: [PATCH 14/57] chore: use proper tag --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 2f3154189..9dd5e3213 100644 --- a/action.yml +++ b/action.yml @@ -10,4 +10,4 @@ inputs: required: true runs: using: docker - image: 'docker://ghcr.io/readmeio/rdme:next' + image: 'ghcr.io/readmeio/rdme:8.6.0-next.13' From e97f06268abea2f5e6f600ac4d4349f017027633 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 6 Mar 2023 19:58:48 -0600 Subject: [PATCH 15/57] feat: add logic to update action.yml --- .releaserc.yml | 7 +++++++ bin/set-action-image.js | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100755 bin/set-action-image.js diff --git a/.releaserc.yml b/.releaserc.yml index 2c689d25f..c9e08864a 100644 --- a/.releaserc.yml +++ b/.releaserc.yml @@ -9,6 +9,13 @@ plugins: # `npm` must be before `git` so the `npm` command can properly bump # the package*.json files before we commit the changes - '@semantic-release/npm' + - [ + '@semantic-release/exec', + { + # Updates our action.yml file to reflect current Docker image version + 'prepareCmd': './bin/set-action-image.js ${nextRelease.version}', + }, + ] - [ '@semantic-release/git', { diff --git a/bin/set-action-image.js b/bin/set-action-image.js new file mode 100755 index 000000000..c920700d7 --- /dev/null +++ b/bin/set-action-image.js @@ -0,0 +1,38 @@ +#! /usr/bin/env node +const fs = require('fs/promises'); + +const core = require('@actions/core'); +// eslint-disable-next-line import/no-extraneous-dependencies +const jsYaml = require('js-yaml'); + +/** + * Updates our `action.yml` file so it properly points to + * the correct docker image, and also sets a version output + * for usage in subsequent workflow Docker image building steps + * @see {@link https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-docker-container-actions} + * @see {@link https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter} + */ +async function setActionImage() { + // Grab version from args + const newVersion = process.argv.slice(2)?.[0]; + if (!newVersion) { + // eslint-disable-next-line no-console + console.error('Missing version in setActionImage()'); + process.exit(1); + } + // Set GitHub Output + core.setOutput('newVersion', newVersion); + // Grabs Docker image URL from action.yml, updates version value, + // and writes changes back to action.yml file + const actionFile = await fs.readFile('./action.yml', 'utf-8'); + const actionObj = jsYaml.load(actionFile); + const imageURL = new URL(actionObj.runs.image); + imageURL.pathname = imageURL.pathname.replace(/:.*/g, `:${newVersion}`); + actionObj.runs.image = imageURL.toString(); + const actionYaml = jsYaml.dump(actionObj, { lineWidth: -1 }); + await fs.writeFile('./action.yml', actionYaml, { encoding: 'utf-8' }); + // eslint-disable-next-line no-console + console.log('action.yml file successfully updated!'); +} + +setActionImage(); From 997109879502a76f42955e7042f3fecf984a3b50 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 6 Mar 2023 20:01:55 -0600 Subject: [PATCH 16/57] chore: bring back semantic-release --- .github/workflows/release.yml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 87ebbe410..fa054cf47 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,14 +30,16 @@ jobs: - name: Install dependencies and build TS run: npm ci && npm run build - # - name: Install semantic-release and friends - # run: npm i --no-save semantic-release@19 @semantic-release/changelog@6 @semantic-release/exec@6 @semantic-release/git@10 - # - name: Run semantic-release workflow - # env: - # GH_TOKEN: ${{ secrets.RELEASE_GH_TOKEN }} - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - # run: npx semantic-release + - name: Install semantic-release and friends + run: npm i --no-save semantic-release@19 @semantic-release/changelog@6 @semantic-release/exec@6 @semantic-release/git@10 + + - name: Run semantic-release workflow + id: release + env: + GH_TOKEN: ${{ secrets.RELEASE_GH_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + run: npx semantic-release - name: Log in to the Container registry uses: docker/login-action@v2 From 6edaeb5b219a38943ba30a405fec20781d4d1d7b Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 6 Mar 2023 20:07:57 -0600 Subject: [PATCH 17/57] revert: don't use set-version-output file --- .github/workflows/docs.yml | 2 +- .github/workflows/release.yml | 12 ++++++------ bin/set-version-output.js | 6 ++---- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index e07ce11da..e0d105643 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -36,7 +36,7 @@ jobs: uses: jacobtomlinson/gha-find-replace@v3 with: find: 'RDME_VERSION' - replace: ${{ steps.rdme-version.outputs.RDME_LATEST_MAJOR_VERSION }} + replace: ${{ steps.rdme-version.outputs.RDME_VERSION }} regex: false include: documentation/* diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index fa054cf47..601b238a7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,13 +34,17 @@ jobs: run: npm i --no-save semantic-release@19 @semantic-release/changelog@6 @semantic-release/exec@6 @semantic-release/git@10 - name: Run semantic-release workflow - id: release env: GH_TOKEN: ${{ secrets.RELEASE_GH_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} run: npx semantic-release + # TODO: Remove this step and set the previous step id to `release` + - name: Temporarily set version output + id: release + run: ./bin/set-action-image.js 8.6.0-next.13 + - name: Log in to the Container registry uses: docker/login-action@v2 with: @@ -48,10 +52,6 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} - - name: Get current package version - id: rdme-version - run: ./bin/set-version-output.js - - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@v4 @@ -59,7 +59,7 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | - type=semver,pattern={{version}},value=${{ steps.rdme-version.outputs.RDME_PKG_VERSION }} + type=semver,pattern={{version}},value=${{ steps.release.outputs.newVersion }} type=ref,event=branch type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} diff --git a/bin/set-version-output.js b/bin/set-version-output.js index 2bd5c19f1..f4d4a34de 100755 --- a/bin/set-version-output.js +++ b/bin/set-version-output.js @@ -1,18 +1,16 @@ #! /usr/bin/env node const core = require('@actions/core'); -const { getMajorPkgVersion, getNodeVersion, getPkgVersion } = require('../dist/src/lib/getPkgVersion'); +const { getNodeVersion, getMajorPkgVersion } = require('../dist/src/lib/getPkgVersion'); /** * Sets output parameters for GitHub Actions workflow so we can do * a find-and-replace in our docs prior to syncing them to ReadMe - * and also to tag our Docker images properly * Docs: https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter */ async function setOutputs() { + core.setOutput('RDME_VERSION', `v${await getMajorPkgVersion('latest')}`); core.setOutput('NODE_VERSION', getNodeVersion()); - core.setOutput('RDME_LATEST_MAJOR_VERSION', `v${await getMajorPkgVersion('latest')}`); - core.setOutput('RDME_PKG_VERSION', await getPkgVersion()); } setOutputs(); From 45ebba0dc68c205c978935dcaff1c678bc9ee423 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 6 Mar 2023 20:13:47 -0600 Subject: [PATCH 18/57] fix: oops --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 9dd5e3213..7b59df6ce 100644 --- a/action.yml +++ b/action.yml @@ -10,4 +10,4 @@ inputs: required: true runs: using: docker - image: 'ghcr.io/readmeio/rdme:8.6.0-next.13' + image: 'docker://ghcr.io/readmeio/rdme:8.6.0-next.13' From ff8bb5493470573a0d05876a6a685c7130ee524e Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 6 Mar 2023 20:21:36 -0600 Subject: [PATCH 19/57] chore: try pushing and seeing what happens --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 601b238a7..59d9342f4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -60,7 +60,6 @@ jobs: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=semver,pattern={{version}},value=${{ steps.release.outputs.newVersion }} - type=ref,event=branch type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} - name: Build (but do NOT push) @@ -68,4 +67,5 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} labels: ${{ steps.meta.outputs.labels }} + push: true tags: ${{ steps.meta.outputs.tags }} From 8ca65455a7d67f5f495460191cc352449825e182 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 6 Mar 2023 20:22:02 -0600 Subject: [PATCH 20/57] Revert "chore: try pushing and seeing what happens" This reverts commit ff8bb5493470573a0d05876a6a685c7130ee524e. --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 59d9342f4..601b238a7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -60,6 +60,7 @@ jobs: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=semver,pattern={{version}},value=${{ steps.release.outputs.newVersion }} + type=ref,event=branch type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} - name: Build (but do NOT push) @@ -67,5 +68,4 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} labels: ${{ steps.meta.outputs.labels }} - push: true tags: ${{ steps.meta.outputs.tags }} From 75438cde7142c5566b40c6d58d80f49282bccff9 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 6 Mar 2023 20:27:20 -0600 Subject: [PATCH 21/57] revert: bring back branch protections --- .github/workflows/release.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 601b238a7..2eb5f3ec4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,9 +1,9 @@ name: Release on: push: - # branches: - # - main - # - next + branches: + - main + - next env: REGISTRY: ghcr.io From e20f17faeb0c0ba4e198b803c9104a21f9fa4808 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 6 Mar 2023 20:31:12 -0600 Subject: [PATCH 22/57] chore(temp): does it publish properly ... without the permissions object? --- .github/workflows/release.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2eb5f3ec4..31be89f98 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,9 +1,9 @@ name: Release on: push: - branches: - - main - - next + # branches: + # - main + # - next env: REGISTRY: ghcr.io @@ -12,9 +12,9 @@ env: jobs: release: runs-on: ubuntu-latest - permissions: - contents: read - packages: write + # permissions: + # contents: read + # packages: write steps: - uses: actions/checkout@v3 @@ -60,7 +60,6 @@ jobs: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=semver,pattern={{version}},value=${{ steps.release.outputs.newVersion }} - type=ref,event=branch type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} - name: Build (but do NOT push) @@ -69,3 +68,4 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} labels: ${{ steps.meta.outputs.labels }} tags: ${{ steps.meta.outputs.tags }} + push: true From ed79ea852cd6387c0e11abbdad7d3918e6981285 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 6 Mar 2023 20:34:47 -0600 Subject: [PATCH 23/57] revert: revert but also remove permissions obj This reverts commit e20f17faeb0c0ba4e198b803c9104a21f9fa4808. --- .github/workflows/release.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 31be89f98..79f7e47bd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,9 +1,9 @@ name: Release on: push: - # branches: - # - main - # - next + branches: + - main + - next env: REGISTRY: ghcr.io @@ -12,10 +12,6 @@ env: jobs: release: runs-on: ubuntu-latest - # permissions: - # contents: read - # packages: write - steps: - uses: actions/checkout@v3 with: @@ -60,6 +56,7 @@ jobs: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} tags: | type=semver,pattern={{version}},value=${{ steps.release.outputs.newVersion }} + type=ref,event=branch type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} - name: Build (but do NOT push) @@ -68,4 +65,3 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} labels: ${{ steps.meta.outputs.labels }} tags: ${{ steps.meta.outputs.tags }} - push: true From ce56860a9c686678787143cc9d8a200518194fa1 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 6 Mar 2023 20:35:01 -0600 Subject: [PATCH 24/57] chore: add comment --- .github/workflows/release.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 79f7e47bd..68f72ecda 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -54,6 +54,10 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + # For every release we had 2-3 tags to the docker build: + # 1. A semver tag (e.g., 8.0.0, 8.0.0-next.0) + # 2. A branch tag (e.g., next, main) + # 3. A `latest` tag (only on the main branch) tags: | type=semver,pattern={{version}},value=${{ steps.release.outputs.newVersion }} type=ref,event=branch From 8881d42e0fee4c7cfc03f65f53f3de10f39c68b5 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 6 Mar 2023 20:36:35 -0600 Subject: [PATCH 25/57] chore: i don't think we need this i'm gonna be so mad if we do lol --- .github/workflows/release.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 68f72ecda..f0c8c41eb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -66,6 +66,5 @@ jobs: - name: Build (but do NOT push) uses: docker/build-push-action@v4 with: - github-token: ${{ secrets.GITHUB_TOKEN }} labels: ${{ steps.meta.outputs.labels }} tags: ${{ steps.meta.outputs.tags }} From 54627b6f03454ece23aaf45e61cd64562408c43d Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 6 Mar 2023 20:37:21 -0600 Subject: [PATCH 26/57] chore: sigh ok try this again --- .github/workflows/release.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f0c8c41eb..44bb67e8a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,9 +1,9 @@ name: Release on: push: - branches: - - main - - next + # branches: + # - main + # - next env: REGISTRY: ghcr.io @@ -60,7 +60,6 @@ jobs: # 3. A `latest` tag (only on the main branch) tags: | type=semver,pattern={{version}},value=${{ steps.release.outputs.newVersion }} - type=ref,event=branch type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} - name: Build (but do NOT push) @@ -68,3 +67,4 @@ jobs: with: labels: ${{ steps.meta.outputs.labels }} tags: ${{ steps.meta.outputs.tags }} + push: true From 0d06366667cf67f68ae2574d53dba7e1df8052f7 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 6 Mar 2023 20:37:35 -0600 Subject: [PATCH 27/57] Revert "chore: sigh ok try this again" This reverts commit 54627b6f03454ece23aaf45e61cd64562408c43d. --- .github/workflows/release.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 44bb67e8a..f0c8c41eb 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,9 +1,9 @@ name: Release on: push: - # branches: - # - main - # - next + branches: + - main + - next env: REGISTRY: ghcr.io @@ -60,6 +60,7 @@ jobs: # 3. A `latest` tag (only on the main branch) tags: | type=semver,pattern={{version}},value=${{ steps.release.outputs.newVersion }} + type=ref,event=branch type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} - name: Build (but do NOT push) @@ -67,4 +68,3 @@ jobs: with: labels: ${{ steps.meta.outputs.labels }} tags: ${{ steps.meta.outputs.tags }} - push: true From c690946563e332f0b30aab3329222c11d467f6fd Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 6 Mar 2023 20:46:36 -0600 Subject: [PATCH 28/57] fix: add action.yml to files we commit --- .releaserc.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.releaserc.yml b/.releaserc.yml index c9e08864a..87d419daa 100644 --- a/.releaserc.yml +++ b/.releaserc.yml @@ -19,10 +19,7 @@ plugins: - [ '@semantic-release/git', { - # TODO: once docker builds are a thing, we're going to have to manually add the assets - # since we're also updating the action.yml file with every release! - # Uncomment this line below once those changes are live: - # assets: ['action.yml', 'CHANGELOG.md', 'package.json', 'package-lock.json'], + assets: ['action.yml', 'CHANGELOG.md', 'package.json', 'package-lock.json'], message: "build(release): 🚀 v${nextRelease.version} 🦉\n\n${nextRelease.notes}\n[skip ci]", }, ] From d67e7e61cce925a890214dd46a3a666ae964083d Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 6 Mar 2023 20:48:03 -0600 Subject: [PATCH 29/57] chore: see if this builds image properly --- .github/workflows/ci.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4c1ea763a..cc47ea3d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,6 +51,13 @@ jobs: path: oas-examples-repo repository: readmeio/oas-examples + - name: Update action.yml to build locally + uses: jacobtomlinson/gha-find-replace@v3 + with: + find: 'image:.*' + replace: "image: 'Dockerfile'" + include: rdme-repo/action.yml + - name: Run `openapi:validate` command uses: ./rdme-repo/ with: From f57d8cc9a7628a6e04a2a53914feba85bcff612d Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 6 Mar 2023 20:55:59 -0600 Subject: [PATCH 30/57] chore: add comment, update another workflow --- .github/workflows/ci.yml | 7 ++++++- .github/workflows/docs.yml | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cc47ea3d9..5bdeeef1c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -51,7 +51,12 @@ jobs: path: oas-examples-repo repository: readmeio/oas-examples - - name: Update action.yml to build locally + # For every GitHub Action release, we deploy our Docker images + # to the GitHub Container Registry for performance reasons. + # Instead of testing against the pre-built image, we can build + # an image from the currently checked-out repo contents by doing a + # li'l update in the action.yml file to point to the current Dockerfile. + - name: Replace Docker image value in action.yml uses: jacobtomlinson/gha-find-replace@v3 with: find: 'image:.*' diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index e0d105643..bbf338646 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -40,6 +40,18 @@ jobs: regex: false include: documentation/* + # For every GitHub Action release, we deploy our Docker images + # to the GitHub Container Registry for performance reasons. + # Instead of testing against the pre-built image, we can build + # an image from the currently checked-out repo contents by doing a + # li'l update in the action.yml file to point to the current Dockerfile. + - name: Replace Docker image value in action.yml + uses: jacobtomlinson/gha-find-replace@v3 + with: + find: 'image:.*' + replace: "image: 'Dockerfile'" + include: action.yml + # And finally, with our updated documentation, # we run the `rdme` GitHub Action to sync the Markdown file # in the `documentation` directory. From d396f5eff0d09095cd2822ea0bc504fa07f17797 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 7 Mar 2023 10:53:08 -0600 Subject: [PATCH 31/57] fix: new approach to obtaining next version --- .github/workflows/release.yml | 23 ++++++++++++----------- .releaserc.yml | 4 ++++ bin/set-action-image.js | 7 +------ 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f0c8c41eb..3e1ef8fcc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -29,17 +29,11 @@ jobs: - name: Install semantic-release and friends run: npm i --no-save semantic-release@19 @semantic-release/changelog@6 @semantic-release/exec@6 @semantic-release/git@10 - - name: Run semantic-release workflow - env: - GH_TOKEN: ${{ secrets.RELEASE_GH_TOKEN }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - run: npx semantic-release - - # TODO: Remove this step and set the previous step id to `release` - - name: Temporarily set version output + # We do a dry run here to analyze the commits and grab the next version + # for usage in the Docker metadata action + - name: Dry run of semantic-release workflow + run: npx semantic-release --dry-run id: release - run: ./bin/set-action-image.js 8.6.0-next.13 - name: Log in to the Container registry uses: docker/login-action@v2 @@ -59,10 +53,17 @@ jobs: # 2. A branch tag (e.g., next, main) # 3. A `latest` tag (only on the main branch) tags: | - type=semver,pattern={{version}},value=${{ steps.release.outputs.newVersion }} + type=semver,pattern={{version}},value=${{ steps.release.outputs.nextVersion }} type=ref,event=branch type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} + - name: Run semantic-release workflow + env: + GH_TOKEN: ${{ secrets.RELEASE_GH_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + run: npx semantic-release + - name: Build (but do NOT push) uses: docker/build-push-action@v4 with: diff --git a/.releaserc.yml b/.releaserc.yml index 87d419daa..b835ea84d 100644 --- a/.releaserc.yml +++ b/.releaserc.yml @@ -12,6 +12,10 @@ plugins: - [ '@semantic-release/exec', { + # Sets the next version as a GitHub Actions output parameter + # for usage in subsequent workflow steps + # https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter + 'verifyReleaseCmd': 'echo nextVersion=${nextRelease.version} >> $GITHUB_OUTPUT', # Updates our action.yml file to reflect current Docker image version 'prepareCmd': './bin/set-action-image.js ${nextRelease.version}', }, diff --git a/bin/set-action-image.js b/bin/set-action-image.js index c920700d7..6a3389778 100755 --- a/bin/set-action-image.js +++ b/bin/set-action-image.js @@ -1,16 +1,13 @@ #! /usr/bin/env node const fs = require('fs/promises'); -const core = require('@actions/core'); // eslint-disable-next-line import/no-extraneous-dependencies const jsYaml = require('js-yaml'); /** * Updates our `action.yml` file so it properly points to - * the correct docker image, and also sets a version output - * for usage in subsequent workflow Docker image building steps + * the correct docker image * @see {@link https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-docker-container-actions} - * @see {@link https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter} */ async function setActionImage() { // Grab version from args @@ -20,8 +17,6 @@ async function setActionImage() { console.error('Missing version in setActionImage()'); process.exit(1); } - // Set GitHub Output - core.setOutput('newVersion', newVersion); // Grabs Docker image URL from action.yml, updates version value, // and writes changes back to action.yml file const actionFile = await fs.readFile('./action.yml', 'utf-8'); From 76df7b0e7869ebee1a88f4877e125df3e710ebeb Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 7 Mar 2023 10:54:13 -0600 Subject: [PATCH 32/57] chore: see if this works --- .github/workflows/release.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3e1ef8fcc..8577cc362 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -35,6 +35,9 @@ jobs: run: npx semantic-release --dry-run id: release + # TODO: remove this! just seeing if docker is a thing in GHA runners + - run: docker -v + - name: Log in to the Container registry uses: docker/login-action@v2 with: From c9c4f1fe8e7276bd981a56bbf1a6bf35075a01cb Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 7 Mar 2023 10:54:40 -0600 Subject: [PATCH 33/57] chore: sigh --- .github/workflows/release.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8577cc362..adbdad9de 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,9 +1,9 @@ name: Release on: push: - branches: - - main - - next + # branches: + # - main + # - next env: REGISTRY: ghcr.io From f968a7c38fe55677c0df4c8fcd2634ad5c2f63d0 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 7 Mar 2023 11:01:43 -0600 Subject: [PATCH 34/57] chore: add comments, rearrange --- .releaserc.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.releaserc.yml b/.releaserc.yml index b835ea84d..bb960dfcc 100644 --- a/.releaserc.yml +++ b/.releaserc.yml @@ -12,11 +12,8 @@ plugins: - [ '@semantic-release/exec', { - # Sets the next version as a GitHub Actions output parameter - # for usage in subsequent workflow steps - # https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter - 'verifyReleaseCmd': 'echo nextVersion=${nextRelease.version} >> $GITHUB_OUTPUT', - # Updates our action.yml file to reflect current Docker image version + # Updates our action.yml file to reflect current Docker image version. + # This needs to happen before `git` so we can to commit this file 'prepareCmd': './bin/set-action-image.js ${nextRelease.version}', }, ] @@ -30,6 +27,9 @@ plugins: - [ '@semantic-release/exec', { + # Sets the next version as a GitHub Actions output parameter for usage in subsequent workflow steps + # https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter + 'verifyReleaseCmd': 'echo nextVersion=${nextRelease.version} >> $GITHUB_OUTPUT', # Adds a couple extra tags as aliases for our GitHub Actions users 'prepareCmd': 'git tag ${nextRelease.version} && ./bin/set-major-version-tag.js', # Lightweight alternative to `@semantic-release/github` that creates a draft release From e9fc133ae47bfa50b4fa916ebbb13f3bb710e003 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 7 Mar 2023 11:01:57 -0600 Subject: [PATCH 35/57] revert: remove docker -v --- .github/workflows/release.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index adbdad9de..389b30425 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -35,9 +35,6 @@ jobs: run: npx semantic-release --dry-run id: release - # TODO: remove this! just seeing if docker is a thing in GHA runners - - run: docker -v - - name: Log in to the Container registry uses: docker/login-action@v2 with: From 9eb20146371469a48758175952b3dfd42a6c45c8 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 7 Mar 2023 11:02:16 -0600 Subject: [PATCH 36/57] chore: temporarily run semantic-release on this branch --- .github/workflows/release.yml | 2 +- .releaserc.yml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 389b30425..e69ff5b9d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -62,7 +62,7 @@ jobs: GH_TOKEN: ${{ secrets.RELEASE_GH_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - run: npx semantic-release + run: npx semantic-release -d - name: Build (but do NOT push) uses: docker/build-push-action@v4 diff --git a/.releaserc.yml b/.releaserc.yml index bb960dfcc..7a0abbe27 100644 --- a/.releaserc.yml +++ b/.releaserc.yml @@ -1,7 +1,8 @@ branches: - name: main - - name: next + - name: container-registry-v2 prerelease: true + channel: next plugins: - '@semantic-release/commit-analyzer' - '@semantic-release/release-notes-generator' From ff209e1411b4584a6c1f66cb4be5b88e57c82314 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 7 Mar 2023 11:04:09 -0600 Subject: [PATCH 37/57] fix: add back npm token --- .github/workflows/release.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e69ff5b9d..6334e330f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,6 +34,8 @@ jobs: - name: Dry run of semantic-release workflow run: npx semantic-release --dry-run id: release + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - name: Log in to the Container registry uses: docker/login-action@v2 From 44a3e09915b12f8e61b72355138738bfb3dc2b72 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 7 Mar 2023 11:24:13 -0600 Subject: [PATCH 38/57] fix: add verification for docker and gh CLIs --- .releaserc.yml | 2 ++ bin/verify-clis.sh | 15 +++++++++++++++ 2 files changed, 17 insertions(+) create mode 100755 bin/verify-clis.sh diff --git a/.releaserc.yml b/.releaserc.yml index 7a0abbe27..d4aff3212 100644 --- a/.releaserc.yml +++ b/.releaserc.yml @@ -28,6 +28,8 @@ plugins: - [ '@semantic-release/exec', { + # Verify existence of gh and docker CLIs + 'verifyConditionsCmd': './bin/verify-clis.sh', # Sets the next version as a GitHub Actions output parameter for usage in subsequent workflow steps # https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter 'verifyReleaseCmd': 'echo nextVersion=${nextRelease.version} >> $GITHUB_OUTPUT', diff --git a/bin/verify-clis.sh b/bin/verify-clis.sh new file mode 100755 index 000000000..11f9509d7 --- /dev/null +++ b/bin/verify-clis.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Verify existence of gh and docker CLIs +# https://stackoverflow.com/a/677212 +set -e +if ! command -v docker &> /dev/null +then + echo "docker could not be found" + exit 1 +fi +if ! command -v gh &> /dev/null +then + echo "gh could not be found" + exit 1 +fi From 32f2fd7a39095a7ea79c548a23c4ecaf2b435cf6 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 7 Mar 2023 12:08:49 -0600 Subject: [PATCH 39/57] fix: typo --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6334e330f..48b01f973 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -50,7 +50,7 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} - # For every release we had 2-3 tags to the docker build: + # For every release we add 2-3 tags to the docker build: # 1. A semver tag (e.g., 8.0.0, 8.0.0-next.0) # 2. A branch tag (e.g., next, main) # 3. A `latest` tag (only on the main branch) From f58afebdd204c21129c279119ae22bdfd5a3b439 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 7 Mar 2023 12:10:05 -0600 Subject: [PATCH 40/57] chore: temporarily break it to see what happens --- bin/verify-clis.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/verify-clis.sh b/bin/verify-clis.sh index 11f9509d7..6b4ff7571 100755 --- a/bin/verify-clis.sh +++ b/bin/verify-clis.sh @@ -3,7 +3,7 @@ # Verify existence of gh and docker CLIs # https://stackoverflow.com/a/677212 set -e -if ! command -v docker &> /dev/null +if ! command -v dockerasdf &> /dev/null then echo "docker could not be found" exit 1 From 091ea7075909bcc0c834fd597788e972629c5b8f Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 7 Mar 2023 12:10:11 -0600 Subject: [PATCH 41/57] Revert "chore: temporarily break it to see what happens" This reverts commit f58afebdd204c21129c279119ae22bdfd5a3b439. --- bin/verify-clis.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/verify-clis.sh b/bin/verify-clis.sh index 6b4ff7571..11f9509d7 100755 --- a/bin/verify-clis.sh +++ b/bin/verify-clis.sh @@ -3,7 +3,7 @@ # Verify existence of gh and docker CLIs # https://stackoverflow.com/a/677212 set -e -if ! command -v dockerasdf &> /dev/null +if ! command -v docker &> /dev/null then echo "docker could not be found" exit 1 From e12ebad491d1a7004d06a7ce46b6cdf208e8bbeb Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 7 Mar 2023 12:11:46 -0600 Subject: [PATCH 42/57] chore: clearer error message --- bin/verify-clis.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/verify-clis.sh b/bin/verify-clis.sh index 11f9509d7..5999cc9a1 100755 --- a/bin/verify-clis.sh +++ b/bin/verify-clis.sh @@ -5,11 +5,11 @@ set -e if ! command -v docker &> /dev/null then - echo "docker could not be found" + echo "docker CLI could not be found" exit 1 fi if ! command -v gh &> /dev/null then - echo "gh could not be found" + echo "gh CLI could not be found" exit 1 fi From a344db50a32630bf93965e33f180d99cf1a9cc29 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 21 Mar 2023 16:09:18 -0500 Subject: [PATCH 43/57] refactor: don't use CLI arg the pkg version is bumped in the npm semantic release step so we can simplify this --- .releaserc.yml | 2 +- bin/set-action-image.js | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/.releaserc.yml b/.releaserc.yml index d4aff3212..7d0f97244 100644 --- a/.releaserc.yml +++ b/.releaserc.yml @@ -15,7 +15,7 @@ plugins: { # Updates our action.yml file to reflect current Docker image version. # This needs to happen before `git` so we can to commit this file - 'prepareCmd': './bin/set-action-image.js ${nextRelease.version}', + 'prepareCmd': './bin/set-action-image.js', }, ] - [ diff --git a/bin/set-action-image.js b/bin/set-action-image.js index 6a3389778..40cd90955 100755 --- a/bin/set-action-image.js +++ b/bin/set-action-image.js @@ -4,25 +4,20 @@ const fs = require('fs/promises'); // eslint-disable-next-line import/no-extraneous-dependencies const jsYaml = require('js-yaml'); +const pkg = require('../package.json'); + /** * Updates our `action.yml` file so it properly points to * the correct docker image * @see {@link https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-docker-container-actions} */ async function setActionImage() { - // Grab version from args - const newVersion = process.argv.slice(2)?.[0]; - if (!newVersion) { - // eslint-disable-next-line no-console - console.error('Missing version in setActionImage()'); - process.exit(1); - } // Grabs Docker image URL from action.yml, updates version value, // and writes changes back to action.yml file const actionFile = await fs.readFile('./action.yml', 'utf-8'); const actionObj = jsYaml.load(actionFile); const imageURL = new URL(actionObj.runs.image); - imageURL.pathname = imageURL.pathname.replace(/:.*/g, `:${newVersion}`); + imageURL.pathname = imageURL.pathname.replace(/:.*/g, `:${pkg.version}`); actionObj.runs.image = imageURL.toString(); const actionYaml = jsYaml.dump(actionObj, { lineWidth: -1 }); await fs.writeFile('./action.yml', actionYaml, { encoding: 'utf-8' }); From 064e935860133f2fbe7ba0d6cb84507c65397689 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 21 Mar 2023 16:09:35 -0500 Subject: [PATCH 44/57] chore: remove unnecessary quotes --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 7b59df6ce..5d3929c8d 100644 --- a/action.yml +++ b/action.yml @@ -10,4 +10,4 @@ inputs: required: true runs: using: docker - image: 'docker://ghcr.io/readmeio/rdme:8.6.0-next.13' + image: docker://ghcr.io/readmeio/rdme:8.6.0-next.13 From 088ebcbea6beeb0813fe54c018b2c5729a4ad9fb Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 21 Mar 2023 20:10:35 -0500 Subject: [PATCH 45/57] chore: bump --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 5d3929c8d..f48784344 100644 --- a/action.yml +++ b/action.yml @@ -10,4 +10,4 @@ inputs: required: true runs: using: docker - image: docker://ghcr.io/readmeio/rdme:8.6.0-next.13 + image: docker://ghcr.io/readmeio/rdme:8.6.0-next.15 From 4cb7e684c20f54fe5b3faa7248ea19328bb34976 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 21 Mar 2023 20:24:33 -0500 Subject: [PATCH 46/57] feat: add docker scripts --- .releaserc.yml | 8 ++-- bin/docker.js | 101 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+), 3 deletions(-) create mode 100755 bin/docker.js diff --git a/.releaserc.yml b/.releaserc.yml index 7d0f97244..7064764ed 100644 --- a/.releaserc.yml +++ b/.releaserc.yml @@ -14,8 +14,9 @@ plugins: '@semantic-release/exec', { # Updates our action.yml file to reflect current Docker image version. - # This needs to happen before `git` so we can to commit this file - 'prepareCmd': './bin/set-action-image.js', + # This needs to happen before `git` so we can to commit this file. + # The second command builds the Docker image + 'prepareCmd': './bin/set-action-image.js && ./bin/docker.js build', }, ] - [ @@ -36,6 +37,7 @@ plugins: # Adds a couple extra tags as aliases for our GitHub Actions users 'prepareCmd': 'git tag ${nextRelease.version} && ./bin/set-major-version-tag.js', # Lightweight alternative to `@semantic-release/github` that creates a draft release - 'publishCmd': 'gh release create ${nextRelease.version} --draft --generate-notes', + # The second command pushes the docker image to the registry + 'publishCmd': 'gh release create ${nextRelease.version} --draft --generate-notes && ./bin/docker.js push', }, ] diff --git a/bin/docker.js b/bin/docker.js new file mode 100755 index 000000000..ca2158740 --- /dev/null +++ b/bin/docker.js @@ -0,0 +1,101 @@ +#! /usr/bin/env node +/* eslint-disable no-console */ +const { exec } = require('child_process'); + +/** + * Retrieves and parses the docker image metadata + * @see {@link https://github.com/docker/metadata-action} + */ +function getMetadata() { + try { + const raw = process.env.DOCKER_METADATA_OUTPUT_JSON; + const metadata = JSON.parse(raw); + if (!Object.keys(metadata.labels || {})?.length) { + throw new Error('Invalid shape (missing labels data)'); + } + if (!metadata?.tags?.length) { + throw new Error('Invalid shape (missing tags data)'); + } + return metadata; + } catch (e) { + console.error('Error retrieving docker metadata:', e.message); + return process.exit(1); + } +} + +/** + * Runs command and logs all output + */ +function runCmd(cmd) { + const child = exec(cmd, (err, stdout, stderr) => { + if (err) { + console.error(err); + process.exit(1); + } + if (stdout) console.log(stdout); + if (stderr) console.error(stderr); + }); + + child.stdout.on('data', chunk => { + console.log(chunk.toString()); + }); + + child.stderr.on('data', chunk => { + console.error(chunk.toString()); + }); +} + +/** + * Constructs and executes `docker build` command + */ +function build() { + const metadata = getMetadata(); + // start constructing command + let cmd = 'docker build --platform linux/amd64'; + // add labels + Object.keys(metadata.labels).forEach(label => { + cmd += ` --label "${label}=${metadata.labels[label]}"`; + }); + // add tags + metadata.tags.forEach(tag => { + cmd += ` --tag ${tag}`; + }); + // point to local Dockerfile + cmd += ' .'; + + console.log(`🐳 🛠️ Running docker build command: ${cmd}`); + + runCmd(cmd); +} + +/** + * Constructs and executes `docker push` command + */ +function push() { + const metadata = getMetadata(); + const image = metadata.tags[0]?.split(':')?.[0]; + + if (!image) { + console.error(`Unable to extract image name from tag: ${metadata.tags[0]}`); + return process.exit(1); + } + + const cmd = `docker push --all-tags ${image}`; + console.log(`🐳 📌 Running docker push command: ${cmd}`); + + return runCmd(cmd); +} + +function run() { + const cmd = process.argv.slice(2)[0]; + if (cmd === 'build') { + return build(); + } else if (cmd === 'push') { + return push(); + } + + console.error("Docker command must be 'build' or 'push'."); + return process.exit(1); +} + +run(); From da2b0b10277d0505d8ea21de1537cd3eecf282a6 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 21 Mar 2023 20:28:44 -0500 Subject: [PATCH 47/57] chore: remove build step --- .github/workflows/release.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8a560f69b..653184818 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -65,9 +65,3 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} run: npx semantic-release -d - - - name: Build (but do NOT push) - uses: docker/build-push-action@v4 - with: - labels: ${{ steps.meta.outputs.labels }} - tags: ${{ steps.meta.outputs.tags }} From 12805d281694a6fa4db1d9add8db1fb8295c551a Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 21 Mar 2023 20:31:27 -0500 Subject: [PATCH 48/57] revert: restore original semantic release branches --- .github/workflows/release.yml | 8 ++++---- .releaserc.yml | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 653184818..4317e2737 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,9 +1,9 @@ name: Release on: push: - # branches: - # - main - # - next + branches: + - main + - next env: REGISTRY: ghcr.io @@ -64,4 +64,4 @@ jobs: GH_TOKEN: ${{ secrets.RELEASE_GH_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - run: npx semantic-release -d + run: npx semantic-release diff --git a/.releaserc.yml b/.releaserc.yml index 7064764ed..5c6c16db8 100644 --- a/.releaserc.yml +++ b/.releaserc.yml @@ -1,8 +1,7 @@ branches: - name: main - - name: container-registry-v2 - prerelease: true - channel: next + - name: next + plugins: - '@semantic-release/commit-analyzer' - '@semantic-release/release-notes-generator' From 4973552d61db2cc9f9b2f9431f3f97d58286e06e Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 21 Mar 2023 20:33:17 -0500 Subject: [PATCH 49/57] chore: temporarily point to previous commit --- .github/workflows/docs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index bbf338646..61428e5a9 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -60,7 +60,7 @@ jobs: # First we're going to perform a dry run of syncing process. # We do this on every push to ensure that an actual sync will work properly - name: Sync docs to ReadMe (dry run) - uses: ./ + uses: readmeio/rdme@088ebcbea6beeb0813fe54c018b2c5729a4ad9fb with: rdme: docs ./documentation --key=${{ secrets.README_DEVELOPERS_API_KEY }} --version=${{ vars.README_DEVELOPERS_MAIN_VERSION }} --dryRun From 4491dc50858b79cbe6b7dfcdcc9ac2724d31c733 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 21 Mar 2023 20:33:23 -0500 Subject: [PATCH 50/57] Revert "chore: temporarily point to previous commit" This reverts commit 4973552d61db2cc9f9b2f9431f3f97d58286e06e. --- .github/workflows/docs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 61428e5a9..bbf338646 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -60,7 +60,7 @@ jobs: # First we're going to perform a dry run of syncing process. # We do this on every push to ensure that an actual sync will work properly - name: Sync docs to ReadMe (dry run) - uses: readmeio/rdme@088ebcbea6beeb0813fe54c018b2c5729a4ad9fb + uses: ./ with: rdme: docs ./documentation --key=${{ secrets.README_DEVELOPERS_API_KEY }} --version=${{ vars.README_DEVELOPERS_MAIN_VERSION }} --dryRun From 30bf0dcc99eb2a8fca40ebe9772590116548d7c8 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 21 Mar 2023 20:35:58 -0500 Subject: [PATCH 51/57] chore: oops --- .releaserc.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.releaserc.yml b/.releaserc.yml index 5c6c16db8..ccbd47ce6 100644 --- a/.releaserc.yml +++ b/.releaserc.yml @@ -1,6 +1,7 @@ branches: - name: main - name: next + prerelease: true plugins: - '@semantic-release/commit-analyzer' From a89024d0a3da91538a3bd23b67b07c2a33e9f29c Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Wed, 22 Mar 2023 10:35:43 -0500 Subject: [PATCH 52/57] refactor: consolidate build + push also clean up a bunch of comments --- .releaserc.yml | 19 +++++++------ bin/docker.js | 76 ++++++++++++++++++++++---------------------------- 2 files changed, 43 insertions(+), 52 deletions(-) diff --git a/.releaserc.yml b/.releaserc.yml index ccbd47ce6..b32090332 100644 --- a/.releaserc.yml +++ b/.releaserc.yml @@ -7,16 +7,18 @@ plugins: - '@semantic-release/commit-analyzer' - '@semantic-release/release-notes-generator' - '@semantic-release/changelog' - # `npm` must be before `git` so the `npm` command can properly bump - # the package*.json files before we commit the changes + # `@semantic-release/npm` must be before `@semantic-release/git` + # so the `@semantic-release/npm` plugin can properly update the version + # in the package*.json files before we commit the changes in `@semantic-release/git` - '@semantic-release/npm' - [ '@semantic-release/exec', { - # Updates our action.yml file to reflect current Docker image version. - # This needs to happen before `git` so we can to commit this file. - # The second command builds the Docker image - 'prepareCmd': './bin/set-action-image.js && ./bin/docker.js build', + # Runs two commands: + # 1. Updates our action.yml file to reflect current Docker image version. + # This needs to happen before `@semantic-release/git` so we can commit this file. + # 2. Builds and pushes the Docker image + 'prepareCmd': './bin/set-action-image.js && ./bin/docker.js', }, ] - [ @@ -36,8 +38,7 @@ plugins: 'verifyReleaseCmd': 'echo nextVersion=${nextRelease.version} >> $GITHUB_OUTPUT', # Adds a couple extra tags as aliases for our GitHub Actions users 'prepareCmd': 'git tag ${nextRelease.version} && ./bin/set-major-version-tag.js', - # Lightweight alternative to `@semantic-release/github` that creates a draft release - # The second command pushes the docker image to the registry - 'publishCmd': 'gh release create ${nextRelease.version} --draft --generate-notes && ./bin/docker.js push', + # Lightweight alternative to `@semantic-release/github` that creates a draft GitHub release + 'publishCmd': 'gh release create ${nextRelease.version} --draft --generate-notes', }, ] diff --git a/bin/docker.js b/bin/docker.js index ca2158740..e8c9d4e37 100755 --- a/bin/docker.js +++ b/bin/docker.js @@ -1,6 +1,7 @@ #! /usr/bin/env node /* eslint-disable no-console */ -const { exec } = require('child_process'); +const util = require('util'); // eslint-disable-line unicorn/import-style +const exec = util.promisify(require('child_process').exec); /** * Retrieves and parses the docker image metadata @@ -26,15 +27,10 @@ function getMetadata() { /** * Runs command and logs all output */ -function runCmd(cmd) { - const child = exec(cmd, (err, stdout, stderr) => { - if (err) { - console.error(err); - process.exit(1); - } - if (stdout) console.log(stdout); - if (stderr) console.error(stderr); - }); +async function runCmd(cmd) { + // https://stackoverflow.com/a/63027900 + const execCmd = exec(cmd); + const child = execCmd.child; child.stdout.on('data', chunk => { console.log(chunk.toString()); @@ -43,59 +39,53 @@ function runCmd(cmd) { child.stderr.on('data', chunk => { console.error(chunk.toString()); }); + + const { stdout, stderr } = await execCmd; + + if (stdout) console.log(stdout); + if (stderr) console.error(stdout); + + return Promise.resolve(); } /** - * Constructs and executes `docker build` command + * Constructs and executes `docker build` and `docker push` commands */ -function build() { +async function run() { const metadata = getMetadata(); - // start constructing command - let cmd = 'docker build --platform linux/amd64'; + // start constructing build command + let buildCmd = 'docker build --platform linux/amd64'; // add labels Object.keys(metadata.labels).forEach(label => { - cmd += ` --label "${label}=${metadata.labels[label]}"`; + buildCmd += ` --label "${label}=${metadata.labels[label]}"`; }); // add tags metadata.tags.forEach(tag => { - cmd += ` --tag ${tag}`; + buildCmd += ` --tag ${tag}`; }); // point to local Dockerfile - cmd += ' .'; - - console.log(`🐳 🛠️ Running docker build command: ${cmd}`); + buildCmd += ' .'; - runCmd(cmd); -} + // Strips tag from image so we can use the --all-tags flag in the push command + const imageWithoutTag = metadata.tags[0]?.split(':')?.[0]; -/** - * Constructs and executes `docker push` command - */ -function push() { - const metadata = getMetadata(); - const image = metadata.tags[0]?.split(':')?.[0]; - - if (!image) { - console.error(`Unable to extract image name from tag: ${metadata.tags[0]}`); + if (!imageWithoutTag) { + console.error(`Unable to separate image name from tag: ${metadata.tags[0]}`); return process.exit(1); } - const cmd = `docker push --all-tags ${image}`; - console.log(`🐳 📌 Running docker push command: ${cmd}`); + const pushCmd = `docker push --all-tags ${imageWithoutTag}`; - return runCmd(cmd); -} + console.log(`🐳 🛠️ Running docker build command: ${buildCmd}`); -function run() { - const cmd = process.argv.slice(2)[0]; - if (cmd === 'build') { - return build(); - } else if (cmd === 'push') { - return push(); - } + await runCmd(buildCmd); + + console.log(`🐳 📌 Running docker push command: ${pushCmd}`); + + await runCmd(pushCmd); - console.error("Docker command must be 'build' or 'push'."); - return process.exit(1); + console.log('🐳 All done!'); + return process.exit(0); } run(); From 3b153c84159182499e7dd66fcc276cfcb05e1bfd Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Wed, 22 Mar 2023 10:54:56 -0500 Subject: [PATCH 53/57] chore: more error handling --- bin/docker.js | 58 +++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/bin/docker.js b/bin/docker.js index e8c9d4e37..a75325cc2 100755 --- a/bin/docker.js +++ b/bin/docker.js @@ -44,8 +44,6 @@ async function runCmd(cmd) { if (stdout) console.log(stdout); if (stderr) console.error(stdout); - - return Promise.resolve(); } /** @@ -53,36 +51,42 @@ async function runCmd(cmd) { */ async function run() { const metadata = getMetadata(); - // start constructing build command - let buildCmd = 'docker build --platform linux/amd64'; - // add labels - Object.keys(metadata.labels).forEach(label => { - buildCmd += ` --label "${label}=${metadata.labels[label]}"`; - }); - // add tags - metadata.tags.forEach(tag => { - buildCmd += ` --tag ${tag}`; - }); - // point to local Dockerfile - buildCmd += ' .'; - - // Strips tag from image so we can use the --all-tags flag in the push command - const imageWithoutTag = metadata.tags[0]?.split(':')?.[0]; - - if (!imageWithoutTag) { - console.error(`Unable to separate image name from tag: ${metadata.tags[0]}`); - return process.exit(1); - } + try { + // start constructing build command + let buildCmd = 'docker build --platform linux/amd64'; + // add labels + Object.keys(metadata.labels).forEach(label => { + buildCmd += ` --label "${label}=${metadata.labels[label]}"`; + }); + // add tags + metadata.tags.forEach(tag => { + buildCmd += ` --tag ${tag}`; + }); + // point to local Dockerfile + buildCmd += ' .'; + + // Strips tag from image so we can use the --all-tags flag in the push command + const imageWithoutTag = metadata.tags[0]?.split(':')?.[0]; + + if (!imageWithoutTag) { + console.error(`Unable to separate image name from tag: ${metadata.tags[0]}`); + return process.exit(1); + } - const pushCmd = `docker push --all-tags ${imageWithoutTag}`; + const pushCmd = `docker push --all-tags ${imageWithoutTag}`; - console.log(`🐳 🛠️ Running docker build command: ${buildCmd}`); + console.log(`🐳 🛠️ Running docker build command: ${buildCmd}`); - await runCmd(buildCmd); + await runCmd(buildCmd); - console.log(`🐳 📌 Running docker push command: ${pushCmd}`); + console.log(`🐳 📌 Running docker push command: ${pushCmd}`); - await runCmd(pushCmd); + await runCmd(pushCmd); + } catch (e) { + console.error('Error running Docker script!'); + console.error(e); + return process.exit(1); + } console.log('🐳 All done!'); return process.exit(0); From 52d80d4640f2900c474c345dda4382cdee0eb40c Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Wed, 22 Mar 2023 19:50:31 -0500 Subject: [PATCH 54/57] fix: pin `pkg` version feedback: https://github.com/readmeio/rdme/pull/777#discussion_r1145516673 --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index af92766b9..79dcb6218 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,7 +2,7 @@ FROM node:16-alpine as builder COPY . /rdme -RUN cd /rdme && npm ci && npm run build && npx pkg . --target host --out-path exe +RUN cd /rdme && npm ci && npm run build && npx pkg@5 . --target host --out-path exe FROM alpine:3.14 From 1b07bb7def65224317d2dc1f38e88516a46af38f Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Thu, 23 Mar 2023 10:14:10 -0500 Subject: [PATCH 55/57] refactor: use `execFile` instead feedback: https://github.com/readmeio/rdme/pull/777#discussion_r1145528308 --- bin/docker.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/bin/docker.js b/bin/docker.js index a75325cc2..882443b7a 100755 --- a/bin/docker.js +++ b/bin/docker.js @@ -1,7 +1,7 @@ #! /usr/bin/env node /* eslint-disable no-console */ const util = require('util'); // eslint-disable-line unicorn/import-style -const exec = util.promisify(require('child_process').exec); +const execFile = util.promisify(require('child_process').execFile); /** * Retrieves and parses the docker image metadata @@ -27,9 +27,9 @@ function getMetadata() { /** * Runs command and logs all output */ -async function runCmd(cmd) { - // https://stackoverflow.com/a/63027900 - const execCmd = exec(cmd); +async function runDockerCmd(args) { + // Promise-based approach grabbed from here: https://stackoverflow.com/a/63027900 + const execCmd = execFile('docker', args); const child = execCmd.child; child.stdout.on('data', chunk => { @@ -50,38 +50,38 @@ async function runCmd(cmd) { * Constructs and executes `docker build` and `docker push` commands */ async function run() { - const metadata = getMetadata(); + const { labels, tags } = getMetadata(); try { // start constructing build command - let buildCmd = 'docker build --platform linux/amd64'; + const buildArgs = ['build', '--platform', 'linux/amd64']; // add labels - Object.keys(metadata.labels).forEach(label => { - buildCmd += ` --label "${label}=${metadata.labels[label]}"`; + Object.keys(labels).forEach(label => { + buildArgs.push('--label', `${label}=${labels[label]}`); }); // add tags - metadata.tags.forEach(tag => { - buildCmd += ` --tag ${tag}`; + tags.forEach(tag => { + buildArgs.push('--tag', tag); }); // point to local Dockerfile - buildCmd += ' .'; + buildArgs.push('.'); // Strips tag from image so we can use the --all-tags flag in the push command - const imageWithoutTag = metadata.tags[0]?.split(':')?.[0]; + const imageWithoutTag = tags[0]?.split(':')?.[0]; if (!imageWithoutTag) { - console.error(`Unable to separate image name from tag: ${metadata.tags[0]}`); + console.error(`Unable to separate image name from tag: ${tags[0]}`); return process.exit(1); } - const pushCmd = `docker push --all-tags ${imageWithoutTag}`; + const pushArgs = ['push', '--all-tags', imageWithoutTag]; - console.log(`🐳 🛠️ Running docker build command: ${buildCmd}`); + console.log(`🐳 🛠️ Running docker build command: ${buildArgs}`); - await runCmd(buildCmd); + await runDockerCmd(buildArgs); - console.log(`🐳 📌 Running docker push command: ${pushCmd}`); + console.log(`🐳 📌 Running docker push command: ${pushArgs}`); - await runCmd(pushCmd); + await runDockerCmd(pushArgs); } catch (e) { console.error('Error running Docker script!'); console.error(e); From 6b5c0c46498572375b56df9cdce5232693ccae69 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Thu, 23 Mar 2023 10:14:28 -0500 Subject: [PATCH 56/57] chore: add links to JSON metadata example --- bin/docker.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/docker.js b/bin/docker.js index 882443b7a..6710c4a85 100755 --- a/bin/docker.js +++ b/bin/docker.js @@ -6,9 +6,11 @@ const execFile = util.promisify(require('child_process').execFile); /** * Retrieves and parses the docker image metadata * @see {@link https://github.com/docker/metadata-action} + * @see {@link https://gist.github.com/kanadgupta/801c8335e7e2e3d80463c34bdd41c7e6} */ function getMetadata() { try { + // See here for an example JSON output: https://gist.github.com/kanadgupta/801c8335e7e2e3d80463c34bdd41c7e6 const raw = process.env.DOCKER_METADATA_OUTPUT_JSON; const metadata = JSON.parse(raw); if (!Object.keys(metadata.labels || {})?.length) { From a9f14e4acf26d0320e72b3f137a7fa3d9475b772 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Thu, 23 Mar 2023 10:32:02 -0500 Subject: [PATCH 57/57] chore: fix up console statements --- bin/docker.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/docker.js b/bin/docker.js index 6710c4a85..fa6fe4cbd 100755 --- a/bin/docker.js +++ b/bin/docker.js @@ -77,11 +77,11 @@ async function run() { const pushArgs = ['push', '--all-tags', imageWithoutTag]; - console.log(`🐳 🛠️ Running docker build command: ${buildArgs}`); + console.log(`🐳 🛠️ Running docker build command: docker ${buildArgs.join(' ')}`); await runDockerCmd(buildArgs); - console.log(`🐳 📌 Running docker push command: ${pushArgs}`); + console.log(`🐳 📌 Running docker push command: docker ${pushArgs.join(' ')}`); await runDockerCmd(pushArgs); } catch (e) {