From 79e3e67415646a1ac7b46abd6d9041bf9ee2d880 Mon Sep 17 00:00:00 2001 From: PythonGermany <97847597+PythonGermany@users.noreply.github.com> Date: Sun, 16 Mar 2025 16:40:22 +0100 Subject: [PATCH 1/4] feat(cd): Use dynamic username This will allow this workflow to work in forked repos without any changes --- .github/workflows/cd.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index 557c16a..656f386 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -17,7 +17,7 @@ jobs: with: name: ${{ env.PROJECT_NAME }} template: template - arguments: "--template-values-file .github/workflows/template_values.toml --verbose" + arguments: "--template-values-file .github/workflows/template_values.toml -d gh-username=${{ github.repository_owner }} --verbose" - name: Generate lockfile run: | @@ -27,8 +27,8 @@ jobs: - name: Checkout old example uses: actions/checkout@v4 with: - repository: rust-github/rust-gh-example path: old_example + repository: ${{ github.repository_owner }}/${{ env.PROJECT_NAME }} ssh-key: ${{ secrets.GH_EXAMPLE_DEPLOY_SECRET }} - name: move sources, mit license and Cargo.toml from old to new example From 0a93bf8c822df1e3ffb466c342b5a57bb22c820c Mon Sep 17 00:00:00 2001 From: PythonGermany <97847597+PythonGermany@users.noreply.github.com> Date: Sun, 16 Mar 2025 16:47:15 +0100 Subject: [PATCH 2/4] feat(cd): Simplify updating example repo --- .github/workflows/cd.yaml | 31 +++---------------------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index 656f386..5b25be5 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -27,40 +27,15 @@ jobs: - name: Checkout old example uses: actions/checkout@v4 with: - path: old_example repository: ${{ github.repository_owner }}/${{ env.PROJECT_NAME }} + path: ${{ env.PROJECT_NAME }}.old ssh-key: ${{ secrets.GH_EXAMPLE_DEPLOY_SECRET }} - - name: move sources, mit license and Cargo.toml from old to new example - run: | - echo "pwd:" - pwd - echo "ls -al:" - ls -al - rm rust-gh-example/src/main.rs - rm rust-gh-example/Cargo.toml - rm rust-gh-example/LICENSE-MIT - cp old_example/src/* rust-gh-example/src/ - cp old_example/Cargo.toml rust-gh-example/Cargo.toml - cp old_example/LICENSE-MIT rust-gh-example/LICENSE-MIT - name: update example - run: | - mkdir old_sources - mv old_example/src/* old_sources - cd old_example - rm -rf * .gitignore .github/ - echo "ls ../rust-gh-example:" - ls ../rust-gh-example - echo "ls ../rust-gh-example/src:" - ls ../rust-gh-example/src - mv ../rust-gh-example/* ../rust-gh-example/.github ../rust-gh-example/.gitignore . - echo "ls -al:" - ls -al - rm src/* - mv ../old_sources/* src + run: cp -rf ${{ env.PROJECT_NAME }}.old/.git ${{ env.PROJECT_NAME }} - name: commit example run: | - cd old_example + cd ${{ env.PROJECT_NAME }} git config user.name github-actions git config user.email github-actions@github.com git add . From 220ac3eb5c60c5811f436c83ba5d8a6370d1be3a Mon Sep 17 00:00:00 2001 From: PythonGermany <97847597+PythonGermany@users.noreply.github.com> Date: Sat, 22 Mar 2025 12:34:03 +0100 Subject: [PATCH 3/4] feat(cd): Check if repo is empty and initialize it --- .github/workflows/cd.yaml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index 5b25be5..59469c0 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -24,6 +24,21 @@ jobs: cd $PROJECT_NAME cargo generate-lockfile + - name: Check for references + run: | + if git ls-remote --exit-code git@github.com:${{ github.repository_owner }}/${{ env.PROJECT_NAME }}.git; then + echo "References found in the remote repo" + else + echo "No references found in the remote repo" + mkdir tmp && cd tmp + git init + git branch -M main + git remote add origin git@github.com:PythonGermany/rust-gh-example.git + git commit --allow-empty -m "Initial commit" + git push -u origin main + rm -rf tmp + fi + - name: Checkout old example uses: actions/checkout@v4 with: From 17ce85fe674a47dec7b8fe909bd47b342d64b4a6 Mon Sep 17 00:00:00 2001 From: PythonGermany <97847597+PythonGermany@users.noreply.github.com> Date: Sat, 22 Mar 2025 12:36:49 +0100 Subject: [PATCH 4/4] fix(cd): Set git user config --- .github/workflows/cd.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml index 59469c0..ddd9cb0 100644 --- a/.github/workflows/cd.yaml +++ b/.github/workflows/cd.yaml @@ -31,6 +31,8 @@ jobs: else echo "No references found in the remote repo" mkdir tmp && cd tmp + git config user.name github-actions + git config user.email github-actions@github.com git init git branch -M main git remote add origin git@github.com:PythonGermany/rust-gh-example.git