From 7a15d131e28bf47141ea89ba2addcb48da74ca36 Mon Sep 17 00:00:00 2001 From: Sidney Andrews Date: Wed, 9 Oct 2024 16:44:15 -0400 Subject: [PATCH] Initial commit --- .github/workflows/clone.yml | 83 ++++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 36 +++++++++++++++ .github/workflows/replace.cs | 3 ++ .github/workflows/validate.yml | 20 ++++++++ readme.md | 6 +++ 5 files changed, 148 insertions(+) create mode 100644 .github/workflows/clone.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/replace.cs create mode 100644 .github/workflows/validate.yml create mode 100644 readme.md diff --git a/.github/workflows/clone.yml b/.github/workflows/clone.yml new file mode 100644 index 0000000..93da9b4 --- /dev/null +++ b/.github/workflows/clone.yml @@ -0,0 +1,83 @@ +name: Pull latest changes from quickstart repository +on: + workflow_dispatch: + schedule: + - cron: '0 13 * * 1' +jobs: + pull-request-source-repo: + name: Create pull request + runs-on: ubuntu-latest + env: + WORKING_BRANCH: auto + steps: + - name: Get GitHub App token + uses: actions/create-github-app-token@v1 + id: app-token + with: + app-id: ${{ secrets.PORTAL_QUICKSTART_SYNCHRONIZER_APP_ID }} + private-key: ${{ secrets.PORTAL_QUICKSTART_SYNCHRONIZER_PRIVATE_KEY }} + - name: Checkout source repository + uses: actions/checkout@v4 + with: + repository: azure-samples/cosmos-db-nosql-dotnet-quickstart + ref: main + path: source + - name: Checkout target repository + uses: actions/checkout@v4 + with: + token: ${{ steps.app-token.outputs.token }} + ref: ${{ github.head_ref }} + path: target + - name: Get GitHub App User ID + id: get-user-id + env: + GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} + run: echo "user-id=$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT" + - name: Configure git + working-directory: target + run: | + git config --global user.name '${{ steps.app-token.outputs.app-slug }}[bot]' + git config --global user.email '${{ steps.get-user-id.outputs.user-id }}+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com>' + - name: Generate date variables + run: | + echo "CURRENT_DATE=$(date +'%Y-%m-%d')" >> $GITHUB_ENV + echo "WORKING_BRANCH=auto-$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV + - name: Create working branch + working-directory: target + run: git checkout -b $WORKING_BRANCH + - name: Copy source to target + run: cp -ra source/src/. target/ + - name: Change text content + working-directory: target + run: | + content=$(cat .github/workflows/replace.cs) + awk -v content="$content" ' + BEGIN { in_block = 0 } + /^\s*\/\/ / { in_block = 1; print content; next } + /^\s*\/\/ <\/create_client>/ { in_block = 0; next } + !in_block { print } + ' web/Program.cs > web/Program.tmp.cs && mv web/Program.tmp.cs web/Program.cs + - name: Add changes to git + working-directory: target + run: | + git add . + - name: Check if files are changed + id: check-files + working-directory: target + run: | + echo "status=$(git diff --shortstat --staged)" >> $GITHUB_OUTPUT + - name: Commit and push changes + if: ${{ steps.check-files.outputs.status != '' }} + working-directory: target + run: | + git commit -m "Automatically generated commit" + git push --set-upstream origin $WORKING_BRANCH + - name: Create auto-merge pull request + if: ${{ steps.check-files.outputs.status != '' }} + working-directory: target + env: + GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} + run: | + url=$(gh pr create --title "[AUTO] $CURRENT_DATE | Merge latest from source repo" --body "${{ steps.check-files.outputs.status}}" --base main --head $WORKING_BRANCH) + gh pr merge --auto --merge $url + echo $url diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..f0021e7 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,36 @@ +name: Create release for default branch +on: + workflow_dispatch: + push: + branches: + - main +jobs: + create-release: + name: Create release + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Get GitHub App token + uses: actions/create-github-app-token@v1 + id: app-token + with: + app-id: ${{ secrets.PORTAL_QUICKSTART_SYNCHRONIZER_APP_ID }} + private-key: ${{ secrets.PORTAL_QUICKSTART_SYNCHRONIZER_PRIVATE_KEY }} + - name: Generate output + id: generate + run: | + echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT + echo "tag=release-$(date +'%Y%m%d%H%M%S')" >> $GITHUB_OUTPUT + - name: Create compressed folder + run: | + mkdir out + git archive --format=zip --output out/project.zip main + - name: Push release + env: + GITHUB_TOKEN: ${{ steps.app-token.outputs.token }} + run: | + gh release create ${{ steps.generate.outputs.tag }} \ + 'out/project.zip#Project folder' \ + --title 'Release ${{ steps.generate.outputs.date }}' + \ No newline at end of file diff --git a/.github/workflows/replace.cs b/.github/workflows/replace.cs new file mode 100644 index 0000000..41f8184 --- /dev/null +++ b/.github/workflows/replace.cs @@ -0,0 +1,3 @@ + CosmosClient client = new( + connectionString: "" + ); \ No newline at end of file diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml new file mode 100644 index 0000000..8424f4c --- /dev/null +++ b/.github/workflows/validate.yml @@ -0,0 +1,20 @@ +name: Validate project +on: + workflow_dispatch: + pull_request: + branches: + - main +jobs: + validate-dotnet: + name: Validate .NET build and format + runs-on: ubuntu-latest + container: mcr.microsoft.com/dotnet/sdk:8.0 + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Check .NET version + run: dotnet --version + - name: Build .NET solution + run: dotnet build + - name: Check .NET code format + run: dotnet format --verify-no-changes \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..af6144f --- /dev/null +++ b/readme.md @@ -0,0 +1,6 @@ +# Quickstart - Azure Cosmos DB for NoSQL - .NET + +| Task | Link | +| --- | --- | +| Downloaded latest source code | | +| Open in GitHub Codespaces | | \ No newline at end of file