diff --git a/.github/workflows/update-carter-nuget-package-references.yml b/.github/workflows/update-carter-nuget-package-references.yml new file mode 100644 index 0000000..fef9596 --- /dev/null +++ b/.github/workflows/update-carter-nuget-package-references.yml @@ -0,0 +1,60 @@ +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json +name: Update Carter NuGet package references + +on: + workflow_call: + inputs: + includePrerelease: + required: true + type: boolean + description: Whether to include prerelease versions when searching for the latest version of the Carter NuGet package + + commitAndPush: + required: true + type: boolean + description: Whether to commit and push the changes; Useful to test the process by looking at the resulting Git diff + +jobs: + update-carter-package-references: + name: Update Carter NuGet package references + runs-on: ubuntu-latest + + steps: + - name: Check out this repository + uses: actions/checkout@v3 + with: + path: self + + - name: Check out the CarterCommunity/build repository + uses: actions/checkout@v3 + with: + repository: CarterCommunity/build + path: build + + - name: Update package references with latest version from NuGet + run: >- + build/update-carter-package-references/run.ps1 + -RootDirectory (Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'self') + -IncludePrerelease:$${{ inputs.includePrerelease }} + shell: pwsh + + - name: Show Git diff + working-directory: self + run: git diff + + # https://github.com/marketplace/actions/checkout#push-a-commit-using-the-built-in-token + - if: inputs.commitAndPush + name: Commit changes and push if necessary + working-directory: self + run: | + GIT_CHANGES=$(git status --porcelain) + if [ "$GIT_CHANGES" == "" ]; then + echo "No changes to commit" + else + echo "Committing and pushing changes" + git config user.name Jonathan Channon + git config user.email jonathan.channon@gmail.com + git add . + git commit -m "Update Carter NuGet package references" + git push + fi diff --git a/README.md b/README.md index e1e5933..9b97de5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## Reusable bits -This repository contains actions that can be reused in other repositories. +This repository contains actions and workflows that can be reused in other repositories. It currently includes: diff --git a/update-carter-package-references/README.md b/update-carter-package-references/README.md index aadac88..9898298 100644 --- a/update-carter-package-references/README.md +++ b/update-carter-package-references/README.md @@ -5,6 +5,13 @@ The files in this directory can help set up a workflow in other repositories to ### Steps 1. Create a new branch in the target repository. -1. Copy the [`workflow.yml`](./workflow.yml) file in this directory as the `.github/workflows/update-carter-package-references.yml` file in the target repository. +1. Copy the [`workflow.yml`](./workflow.yml) file in this directory to the `.github/workflows` directory in the target repository. 1. Open a pull request. 1. When merged, you will find a new action in the target repository. + +### How it works + +This process takes advantage of [reusable workflows in GitHub Actions](https://docs.github.com/en/actions/using-workflows/reusing-workflows), which avoids having to duplicate logic across several repositories. + +The workflow defined in the `workflow.yml` file calls the workflow located in the [`.github/workflows/update-carter-nuget-package-references.yml`](../.github/workflows/update-carter-nuget-package-references.yml) file in this repository, which contains all the logic. +If in the future, we need to make adjustments to the logic, we'll only have to update a single file, instead of having to go through all the repositories where we might have copied that logic. diff --git a/update-carter-package-references/workflow.yml b/update-carter-package-references/workflow.yml index 3599931..0097935 100644 --- a/update-carter-package-references/workflow.yml +++ b/update-carter-package-references/workflow.yml @@ -16,43 +16,7 @@ on: jobs: update-carter-package-references: - name: Update Carter NuGet package references - runs-on: ubuntu-latest - - steps: - - name: Check out this repository - uses: actions/checkout@v3 - with: - path: self - - - name: Check out the CarterCommunity/.github repository - uses: actions/checkout@v3 - with: - repository: CarterCommunity/.github - path: .github - - - name: Update package references with latest version from NuGet - run: >- - .github/update-carter-package-references/run.ps1 - -RootDirectory (Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'self') - -IncludePrerelease:$${{ github.event.inputs.includePrerelease }} - shell: pwsh - - - name: Show Git diff - run: git diff - - # https://github.com/marketplace/actions/checkout#push-a-commit-using-the-built-in-token - - if: github.event.inputs.commitAndPush - name: Commit changes and push if necessary - run: | - GIT_CHANGES=$(git status --porcelain) - if [ "$GIT_CHANGES" == "" ]; then - echo "No changes to commit" - else - echo "Committing and pushing changes" - git config user.name Jonathan Channon - git config user.email jonathan.channon@gmail.com - git add . - git commit -m "Update Carter NuGet package references" - git push - fi + uses: CarterCommunity/build/.github/workflows/update-carter-package-references.yml@main + with: + includePrerelease: ${{ github.event.inputs.includePrerelease }} + commitAndPush: ${{ github.event.inputs.commitAndPush }}