From dea691c503d0c3f60db73598deaa058b77df33ae Mon Sep 17 00:00:00 2001 From: Joli Lui Date: Wed, 12 Jul 2023 16:37:13 -0400 Subject: [PATCH] create composite actions --- .github/actions/release/action.yml | 36 ++++++++++++++ .github/actions/update-doc/action.yml | 49 +++++++++++++++++++ .../workflows/{tag.yml => cli-release.yml} | 19 +++++-- .github/workflows/release.yml | 22 --------- .github/workflows/update_doc.yml | 49 ------------------- 5 files changed, 101 insertions(+), 74 deletions(-) create mode 100644 .github/actions/release/action.yml create mode 100644 .github/actions/update-doc/action.yml rename .github/workflows/{tag.yml => cli-release.yml} (69%) delete mode 100644 .github/workflows/release.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..bcb09fd8b --- /dev/null +++ b/.github/actions/release/action.yml @@ -0,0 +1,36 @@ +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' + +runs: + using: 'composite' + steps: + # - name: Create GitHub Release + # uses: DevCycleHQ/release-action/gh-release@main + # with: + # draft: true + # prerelease: true + # github-token: ${{ inputs.github-token }} + + # 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 }} + + - 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..a4ed9da83 --- /dev/null +++ b/.github/actions/update-doc/action.yml @@ -0,0 +1,49 @@ +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 + # need to get/update access token + token: ${{ inputs.access_token }} + fetch-depth: 0 + + - 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/tag.yml b/.github/workflows/cli-release.yml similarity index 69% rename from .github/workflows/tag.yml rename to .github/workflows/cli-release.yml index cddb0ce59..ab5ee0d07 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/cli-release.yml @@ -1,4 +1,4 @@ -name: Tag New Version +name: CLI Release on: workflow_dispatch: @@ -8,7 +8,7 @@ permissions: contents: write jobs: - tag-new-version: + cli-release: runs-on: ubuntu-latest steps: - name: Check out code @@ -43,4 +43,17 @@ jobs: 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 + git push --atomic origin main $LATEST_TAG + + - name: Release + uses: ./.github/actions/release + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + release-tag: $LATEST_TAG + + - name: Update Doc + uses: ./.github/actions/update-doc + with: + latest_tag: $LATEST_TAG + # need to get/update access token + access_token: ${{ secrets.PAT_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/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