From 285b372ed7c0417717ae9184bbf6e425ed93712b Mon Sep 17 00:00:00 2001 From: Joli Lui Date: Fri, 7 Jul 2023 09:46:38 -0400 Subject: [PATCH 1/3] feat: add release yaml --- .github/workflows/release.yml | 129 ++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..919acf4b9 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,129 @@ +name: CLI Release + +on: + workflow_dispatch: + # schedule: + # - cron: '0 12 * * 2' # Runs every Tuesday at 12:00 PM (noon) ET + +jobs: + + checks: + runs-on: ubuntu-latest + outputs: + HAS_TAG: ${{ steps.check_tag.outputs.has_tag }} + steps: + - name: Check out code + uses: actions/checkout@v3 + + - name: Check if commit has a new tag + id: check_tag + run: | + if git describe --tags --exact-match HEAD >/dev/null 2>&1; then + echo "has_tag=true" >> $GITHUB_OUTPUT + echo true + else + echo "has_tag=false" >> $GITHUB_OUTPUT + echo false + fi + + release: + runs-on: ubuntu-latest + needs: checks + outputs: + CLI_VERSION: ${{ steps.get_cli_version.outputs.CLI_VERSION }} + if: needs.checks.outputs.HAS_TAG == 'false' + steps: + - name: Check out code + uses: actions/checkout@v3 + + - name: Set Git author + run: | + git config user.name 'github-actions[bot]' + git config user.email 'github-actions[bot]@users.noreply.github.com' + + - name: Get node version + id: get_node_version + run: | + echo "NVMRC=$(cat .nvmrc)" >> $GITHUB_OUTPUT + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: "${{ steps.get_node_version.outputs.NVMRC }}" + + - name: Install dependencies + run: yarn install + + - name: Build + run: yarn build + + - name: Bump CLI version + run: npm version patch --force + + - name: Read version from package.json + id: get_cli_version + run: echo "CLI_VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT + + - name: Get latest tag + id: get_latest_tag + run: echo "LATEST_TAG=$(git describe --abbrev=0 --tags)" >> $GITHUB_OUTPUT + + - name: Commit and push tag to main branch + run: | + git add . + git commit --amend -m "Release v${{ steps.get_cli_version.outputs.CLI_VERSION }}" + git tag -f ${{ steps.get_latest_tag.outputs.LATEST_TAG }} + git push origin main --follow-tags + + - name: Create GitHub Release + uses: ncipollo/release-action@v1 + with: + name: "v${{ steps.get_cli_version.outputs.CLI_VERSION }}" + tag: "v${{ steps.get_cli_version.outputs.CLI_VERSION }}" + generateReleaseNotes: "true" + makeLatest: "true" + + - name: Publish to NPM + run: npm publish --access public + + update_doc: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + needs: release + env: + BRANCH_NAME: update-cli-version-to-v${{ needs.release.outputs.CLI_VERSION }} + steps: + - name: Check out code + uses: actions/checkout@v2 + with: + repository: DevCycleHQ/devcycle-docs + # need access token + token: ${{ secrets.PAT_TOKEN }} + + - name: Set Git author + run: | + git config user.name 'github-actions[bot]' + git config user.email 'github-actions[bot]@users.noreply.github.com' + + - name: Update CLI version in docs repo + run: | + ls -al + echo $BRANCH_NAME + git checkout -b "$BRANCH_NAME" + git branch + sed -i 's/const DVC_CLI_VERSION = .*/const DVC_CLI_VERSION = '\''v${{ needs.release.outputs.CLI_VERSION }}'\'' \/\/ auto updated by dvc cli release workflow/' docusaurus.config.js + git add docusaurus.config.js + git commit -m "Update CLI version to v${{ needs.release.outputs.CLI_VERSION }}" + + - name: Push code to docs repo + run: | + git push --set-upstream origin "$BRANCH_NAME" + + - name: Create PR + env: + # need access token + GH_TOKEN: ${{ secrets.PAT_TOKEN }} + run: gh pr create --repo DevCycleHQ/devcycle-docs --base main --head "$BRANCH_NAME" --title "Update CLI version to v${{ needs.release.outputs.CLI_VERSION }}" --body "This PR was automatically created by the DevCycle CLI release workflow." + From a9d58cee57c286681133828adde3695e15702208 Mon Sep 17 00:00:00 2001 From: Joli Lui Date: Tue, 11 Jul 2023 16:26:08 -0400 Subject: [PATCH 2/3] separate workflow jobs --- .github/workflows/release.yml | 127 +++---------------------------- .github/workflows/tag.yml | 46 +++++++++++ .github/workflows/update_doc.yml | 49 ++++++++++++ 3 files changed, 105 insertions(+), 117 deletions(-) create mode 100644 .github/workflows/tag.yml create mode 100644 .github/workflows/update_doc.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 919acf4b9..38ff43c15 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,129 +1,22 @@ name: CLI Release on: - workflow_dispatch: - # schedule: - # - cron: '0 12 * * 2' # Runs every Tuesday at 12:00 PM (noon) ET + push: + tags: + - '*' jobs: - - checks: - runs-on: ubuntu-latest - outputs: - HAS_TAG: ${{ steps.check_tag.outputs.has_tag }} - steps: - - name: Check out code - uses: actions/checkout@v3 - - - name: Check if commit has a new tag - id: check_tag - run: | - if git describe --tags --exact-match HEAD >/dev/null 2>&1; then - echo "has_tag=true" >> $GITHUB_OUTPUT - echo true - else - echo "has_tag=false" >> $GITHUB_OUTPUT - echo false - fi - release: runs-on: ubuntu-latest - needs: checks - outputs: - CLI_VERSION: ${{ steps.get_cli_version.outputs.CLI_VERSION }} - if: needs.checks.outputs.HAS_TAG == 'false' - steps: - - name: Check out code - uses: actions/checkout@v3 - - - name: Set Git author - run: | - git config user.name 'github-actions[bot]' - git config user.email 'github-actions[bot]@users.noreply.github.com' - - - name: Get node version - id: get_node_version - run: | - echo "NVMRC=$(cat .nvmrc)" >> $GITHUB_OUTPUT - - - name: Set up Node.js - uses: actions/setup-node@v3 - with: - node-version: "${{ steps.get_node_version.outputs.NVMRC }}" - - - name: Install dependencies - run: yarn install - - - name: Build - run: yarn build - - - name: Bump CLI version - run: npm version patch --force - - - name: Read version from package.json - id: get_cli_version - run: echo "CLI_VERSION=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT - - - name: Get latest tag - id: get_latest_tag - run: echo "LATEST_TAG=$(git describe --abbrev=0 --tags)" >> $GITHUB_OUTPUT - - - name: Commit and push tag to main branch - run: | - git add . - git commit --amend -m "Release v${{ steps.get_cli_version.outputs.CLI_VERSION }}" - git tag -f ${{ steps.get_latest_tag.outputs.LATEST_TAG }} - git push origin main --follow-tags - + steps: - name: Create GitHub Release - uses: ncipollo/release-action@v1 + uses: DevCycleHQ/release-action/gh-release@main with: - name: "v${{ steps.get_cli_version.outputs.CLI_VERSION }}" - tag: "v${{ steps.get_cli_version.outputs.CLI_VERSION }}" - generateReleaseNotes: "true" - makeLatest: "true" + draft: true + prerelease: true + github-token: ${{ secrets.GITHUB_TOKEN }} - name: Publish to NPM - run: npm publish --access public - - update_doc: - runs-on: ubuntu-latest - permissions: - contents: write - pull-requests: write - needs: release - env: - BRANCH_NAME: update-cli-version-to-v${{ needs.release.outputs.CLI_VERSION }} - steps: - - name: Check out code - uses: actions/checkout@v2 - with: - repository: DevCycleHQ/devcycle-docs - # need access token - token: ${{ secrets.PAT_TOKEN }} - - - name: Set Git author - run: | - git config user.name 'github-actions[bot]' - git config user.email 'github-actions[bot]@users.noreply.github.com' - - - name: Update CLI version in docs repo - run: | - ls -al - echo $BRANCH_NAME - git checkout -b "$BRANCH_NAME" - git branch - sed -i 's/const DVC_CLI_VERSION = .*/const DVC_CLI_VERSION = '\''v${{ needs.release.outputs.CLI_VERSION }}'\'' \/\/ auto updated by dvc cli release workflow/' docusaurus.config.js - git add docusaurus.config.js - git commit -m "Update CLI version to v${{ needs.release.outputs.CLI_VERSION }}" - - - name: Push code to docs repo - run: | - git push --set-upstream origin "$BRANCH_NAME" - - - name: Create PR env: - # need access token - GH_TOKEN: ${{ secrets.PAT_TOKEN }} - run: gh pr create --repo DevCycleHQ/devcycle-docs --base main --head "$BRANCH_NAME" --title "Update CLI version to v${{ needs.release.outputs.CLI_VERSION }}" --body "This PR was automatically created by the DevCycle CLI release workflow." - + NODE_AUTH_TOKEN: ${{ secrets.NPMJS_ACCESS_TOKEN }} + run: npm publish --access public diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml new file mode 100644 index 000000000..cddb0ce59 --- /dev/null +++ b/.github/workflows/tag.yml @@ -0,0 +1,46 @@ +name: Tag New Version + +on: + workflow_dispatch: + # schedule: + # - cron: '0 12 * * 2' # Runs every Tuesday at 12:00 PM (noon) ET +permissions: + contents: write + +jobs: + tag-new-version: + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Get node version + id: get_node_version + run: | + echo "NVMRC=$(cat .nvmrc)" >> $GITHUB_OUTPUT + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: "${{ steps.get_node_version.outputs.NVMRC }}" + + - name: Install dependencies + run: yarn install + + - name: Build + run: yarn build + + - name: Bump CLI version + run: npm version patch --force + + - name: Get latest tag + run: echo "LATEST_TAG=$(git describe --abbrev=0 --tags)" >> $GITHUB_ENV + + - name: Commit and push tag to main branch + run: | + git add . + git commit --amend -m "Release $LATEST_TAG" + git tag -f $LATEST_TAG + git push origin main --follow-tags \ No newline at end of file diff --git a/.github/workflows/update_doc.yml b/.github/workflows/update_doc.yml new file mode 100644 index 000000000..0997a3354 --- /dev/null +++ b/.github/workflows/update_doc.yml @@ -0,0 +1,49 @@ +name: Update Doc + +on: + workflow_run: + workflows: + - "CLI Release" + types: + - completed + +jobs: + update_doc: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + steps: + - name: Check out code + uses: actions/checkout@v3 + with: + repository: DevCycleHQ/devcycle-docs + # need to get/update access token + token: ${{ secrets.PAT_TOKEN }} + fetch-depth: 0 + + - name: Get latest tag + id: get_latest_tag + run: echo "LATEST_TAG=$(git describe --abbrev=0 --tags)" >> $GITHUB_OUTPUT + + - name: Update CLI version in docs repo + env: + CLI_VERSION: v${{ steps.get_latest_tag.outputs.LATEST_TAG }} + BRANCH_NAME: update-cli-version-to-${{ env.CLI_VERSION }} + run: | + git checkout -b "$BRANCH_NAME" + sed -i 's/const DVC_CLI_VERSION = .*/const DVC_CLI_VERSION = '\''$CLI_VERSION'\'' \/\/ auto updated by dvc cli release workflow/' docusaurus.config.js + git add docusaurus.config.js + git commit -m "Update CLI version to $CLI_VERSION" + + - name: Push code to docs repo + run: | + git push --set-upstream origin "$BRANCH_NAME" + + - name: Create PR + env: + # need to get/update access token + GH_TOKEN: ${{ secrets.PAT_TOKEN }} + CLI_VERSION: v${{ steps.get_latest_tag.outputs.LATEST_TAG }} + BRANCH_NAME: update-cli-version-to-${{ env.CLI_VERSION }} + run: gh pr create --repo DevCycleHQ/devcycle-docs --base main --head "$BRANCH_NAME" --title "Update CLI version to $CLI_VERSION" --body "This PR was automatically created by the DevCycle CLI release workflow." \ No newline at end of file From 7b434316f935a426945f859587482ade230c6b9a Mon Sep 17 00:00:00 2001 From: Joli Lui Date: Wed, 12 Jul 2023 16:37:13 -0400 Subject: [PATCH 3/3] create composite actions --- .github/actions/release/action.yml | 39 ++++++++++++ .github/actions/update-doc/action.yml | 55 +++++++++++++++++ .github/workflows/cli-release.yml | 88 +++++++++++++++++++++++++++ .github/workflows/release.yml | 22 ------- .github/workflows/tag.yml | 46 -------------- .github/workflows/update_doc.yml | 49 --------------- 6 files changed, 182 insertions(+), 117 deletions(-) create mode 100644 .github/actions/release/action.yml create mode 100644 .github/actions/update-doc/action.yml create mode 100644 .github/workflows/cli-release.yml delete mode 100644 .github/workflows/release.yml delete mode 100644 .github/workflows/tag.yml delete mode 100644 .github/workflows/update_doc.yml diff --git a/.github/actions/release/action.yml b/.github/actions/release/action.yml new file mode 100644 index 000000000..4b188df02 --- /dev/null +++ b/.github/actions/release/action.yml @@ -0,0 +1,39 @@ +name: GitHub release and Publish to NPM +description: Create a GitHub release and publish to NPM + +inputs: + github-token: + required: true + description: 'The GitHub token to use for authentication' + release-tag: + required: true + description: 'The tag to use for the release' + draft: + required: false + description: 'Whether to create a draft (unpublished) release' + default: 'true' + prerelease: + required: false + description: 'Whether to create a prerelease release' + default: 'true' + +runs: + using: 'composite' + steps: + # Replace with DevCycleHQ/release-action/gh-release@main when it's ready + - name: Create GitHub Release + uses: ncipollo/release-action@v1 + with: + name: "${{ inputs.release-tag }}" + tag: "${{ inputs.release-tag }}" + generateReleaseNotes: "true" + makeLatest: "true" + token: ${{ inputs.github-token }} + draft: ${{ inputs.draft }} + prerelease: ${{ inputs.prerelease }} + + - name: Publish to NPM + shell: bash + env: + NODE_AUTH_TOKEN: ${{ secrets.NPMJS_ACCESS_TOKEN }} + run: npm publish --access public diff --git a/.github/actions/update-doc/action.yml b/.github/actions/update-doc/action.yml new file mode 100644 index 000000000..a26be4038 --- /dev/null +++ b/.github/actions/update-doc/action.yml @@ -0,0 +1,55 @@ +name: Update Doc + +description: 'Update the CLI version in devcycle-docs' + +inputs: + latest_tag: + required: true + description: 'The latest tag from the workflow that uses this action' + access_token: + required: true + description: 'The access token to use for authentication' + +runs: + using: 'composite' + steps: + - name: Check out code + uses: actions/checkout@v3 + with: + repository: DevCycleHQ/devcycle-docs + path: devcycle-docs + token: ${{ inputs.access_token }} + fetch-depth: 0 + + - name: Set Git author + shell: bash + working-directory: devcycle-docs + run: | + git config --global user.email "github-tracker-bot@taplytics.com" + git config --global user.name "DevCycle Automation" + + - name: Set branch name + shell: bash + working-directory: devcycle-docs + run: echo "BRANCH_NAME=update-cli-version-to-${{ inputs.latest_tag }}" >> $GITHUB_ENV + + - name: Update CLI version in docs repo + shell: bash + working-directory: devcycle-docs + run: | + git checkout -b "$BRANCH_NAME" + sed -i "s/const DVC_CLI_VERSION = .*/const DVC_CLI_VERSION = '${{ inputs.latest_tag }}' \/\/ auto updated by dvc cli release workflow/" docusaurus.config.js + git add docusaurus.config.js + git commit -m "Update CLI version to ${{ inputs.latest_tag }}" + + - name: Push code to docs repo + shell: bash + working-directory: devcycle-docs + run: git push --set-upstream origin "$BRANCH_NAME" + + - name: Create PR + shell: bash + working-directory: devcycle-docs + env: + GH_TOKEN: ${{ inputs.access_token }} + run: gh pr create --repo DevCycleHQ/devcycle-docs --base main --head "$BRANCH_NAME" --title "Update CLI version to $LATEST_TAG" --body "This PR was automatically created by the DevCycle CLI release workflow." diff --git a/.github/workflows/cli-release.yml b/.github/workflows/cli-release.yml new file mode 100644 index 000000000..f8e60d61d --- /dev/null +++ b/.github/workflows/cli-release.yml @@ -0,0 +1,88 @@ +name: CLI Release + +on: + workflow_dispatch: + inputs: + draft-release: + description: 'Draft release?' + required: false + type: boolean + default: true + prerelease: + description: 'Prerelease?' + required: false + type: boolean + default: true + npm-version: + description: 'NPM version bump?' + required: false + type: choice + options: + - major + - minor + - patch + default: 'patch' + + # schedule: + # - cron: '0 12 * * 2' # Runs every Tuesday at 12:00 PM (noon) ET +permissions: + contents: write + +jobs: + cli-release: + runs-on: ubuntu-latest + steps: + - name: Check out code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + token: ${{ secrets.AUTOMATION_USER_TOKEN }} + + - name: Set Git author + run: | + git config --global user.email "github-tracker-bot@taplytics.com" + git config --global user.name "DevCycle Automation" + + - name: Get node version + id: get_node_version + run: | + echo "NVMRC=$(cat .nvmrc)" >> $GITHUB_OUTPUT + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: "${{ steps.get_node_version.outputs.NVMRC }}" + + - name: Install dependencies + run: yarn install + + - name: Build + run: yarn build + + - name: Bump CLI version + run: npm version ${{ inputs.npm-version }} --force + + - name: Get latest tag + run: echo "LATEST_TAG=$(git describe --abbrev=0 --tags)" >> $GITHUB_ENV + + - name: Commit and push tag to main branch + run: | + git add . + git commit --amend -m "Release $LATEST_TAG" + git tag -f $LATEST_TAG + git push --atomic origin main $LATEST_TAG + + - name: Release + uses: ./.github/actions/release + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + # cannot read $LATEST_TAG here so using ${{ env.LATEST_TAG }} + release-tag: ${{ env.LATEST_TAG }} + draft: ${{ inputs.draft-release }} + prerelease: ${{ inputs.prerelease }} + + - name: Update Doc + uses: ./.github/actions/update-doc + with: + latest_tag: $LATEST_TAG + access_token: ${{ secrets.AUTOMATION_USER_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 38ff43c15..000000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: CLI Release - -on: - push: - tags: - - '*' - -jobs: - release: - runs-on: ubuntu-latest - steps: - - name: Create GitHub Release - uses: DevCycleHQ/release-action/gh-release@main - with: - draft: true - prerelease: true - github-token: ${{ secrets.GITHUB_TOKEN }} - - - name: Publish to NPM - env: - NODE_AUTH_TOKEN: ${{ secrets.NPMJS_ACCESS_TOKEN }} - run: npm publish --access public diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml deleted file mode 100644 index cddb0ce59..000000000 --- a/.github/workflows/tag.yml +++ /dev/null @@ -1,46 +0,0 @@ -name: Tag New Version - -on: - workflow_dispatch: - # schedule: - # - cron: '0 12 * * 2' # Runs every Tuesday at 12:00 PM (noon) ET -permissions: - contents: write - -jobs: - tag-new-version: - runs-on: ubuntu-latest - steps: - - name: Check out code - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Get node version - id: get_node_version - run: | - echo "NVMRC=$(cat .nvmrc)" >> $GITHUB_OUTPUT - - - name: Set up Node.js - uses: actions/setup-node@v3 - with: - node-version: "${{ steps.get_node_version.outputs.NVMRC }}" - - - name: Install dependencies - run: yarn install - - - name: Build - run: yarn build - - - name: Bump CLI version - run: npm version patch --force - - - name: Get latest tag - run: echo "LATEST_TAG=$(git describe --abbrev=0 --tags)" >> $GITHUB_ENV - - - name: Commit and push tag to main branch - run: | - git add . - git commit --amend -m "Release $LATEST_TAG" - git tag -f $LATEST_TAG - git push origin main --follow-tags \ No newline at end of file diff --git a/.github/workflows/update_doc.yml b/.github/workflows/update_doc.yml deleted file mode 100644 index 0997a3354..000000000 --- a/.github/workflows/update_doc.yml +++ /dev/null @@ -1,49 +0,0 @@ -name: Update Doc - -on: - workflow_run: - workflows: - - "CLI Release" - types: - - completed - -jobs: - update_doc: - runs-on: ubuntu-latest - permissions: - contents: write - pull-requests: write - steps: - - name: Check out code - uses: actions/checkout@v3 - with: - repository: DevCycleHQ/devcycle-docs - # need to get/update access token - token: ${{ secrets.PAT_TOKEN }} - fetch-depth: 0 - - - name: Get latest tag - id: get_latest_tag - run: echo "LATEST_TAG=$(git describe --abbrev=0 --tags)" >> $GITHUB_OUTPUT - - - name: Update CLI version in docs repo - env: - CLI_VERSION: v${{ steps.get_latest_tag.outputs.LATEST_TAG }} - BRANCH_NAME: update-cli-version-to-${{ env.CLI_VERSION }} - run: | - git checkout -b "$BRANCH_NAME" - sed -i 's/const DVC_CLI_VERSION = .*/const DVC_CLI_VERSION = '\''$CLI_VERSION'\'' \/\/ auto updated by dvc cli release workflow/' docusaurus.config.js - git add docusaurus.config.js - git commit -m "Update CLI version to $CLI_VERSION" - - - name: Push code to docs repo - run: | - git push --set-upstream origin "$BRANCH_NAME" - - - name: Create PR - env: - # need to get/update access token - GH_TOKEN: ${{ secrets.PAT_TOKEN }} - CLI_VERSION: v${{ steps.get_latest_tag.outputs.LATEST_TAG }} - BRANCH_NAME: update-cli-version-to-${{ env.CLI_VERSION }} - run: gh pr create --repo DevCycleHQ/devcycle-docs --base main --head "$BRANCH_NAME" --title "Update CLI version to $CLI_VERSION" --body "This PR was automatically created by the DevCycle CLI release workflow." \ No newline at end of file