Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
seesharprun committed Oct 9, 2024
0 parents commit 7a15d13
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 0 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/clone.yml
Original file line number Diff line number Diff line change
@@ -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*\/\/ <create_client>/ { 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
36 changes: 36 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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 }}'
3 changes: 3 additions & 0 deletions .github/workflows/replace.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CosmosClient client = new(
connectionString: "<azure-cosmos-db-nosql-connection-string>"
);
20 changes: 20 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Quickstart - Azure Cosmos DB for NoSQL - .NET

| Task | Link |
| --- | --- |
| Downloaded latest source code | <https://github.com/azurecosmosdb/quickstart-nosql-dotnet/releases/latest/download/project.zip> |
| Open in GitHub Codespaces | <https://codespaces.new/AzureCosmosDB/quickstart-nosql-dotnet?template=true&quickstart=1> |

0 comments on commit 7a15d13

Please sign in to comment.