From 98919f7175325da38e1e281d95ed205a312415a2 Mon Sep 17 00:00:00 2001 From: Daniel Cazzulino Date: Fri, 5 Aug 2022 18:52:14 -0300 Subject: [PATCH] Use BOT_ defaults consistently --- .github/workflows/changelog.yml | 14 ++---- .github/workflows/defaults/action.yml | 65 +++++++++++++++++++++++++++ .github/workflows/dotnet-file.yml | 22 ++------- .github/workflows/includes.yml | 6 +++ 4 files changed, 79 insertions(+), 28 deletions(-) create mode 100644 .github/workflows/defaults/action.yml diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index b535f6e..0a3d3a9 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -4,18 +4,12 @@ on: types: [released] workflow_dispatch: -env: - GH_TOKEN: ${{ secrets.GH_TOKEN }} - jobs: changelog: runs-on: ubuntu-latest steps: - - name: 🔍 GH_TOKEN - if: env.GH_TOKEN == '' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: echo "GH_TOKEN=${GITHUB_TOKEN}" >> $GITHUB_ENV + - name: 🔍 defaults + uses: ./.github/workflows/defaults - name: 🤘 checkout uses: actions/checkout@v2 @@ -36,7 +30,7 @@ jobs: - name: 🚀 changelog run: | - git config --local user.name github-actions - git config --local user.email github-actions@github.com + git config --local user.name ${BOT_NAME} + git config --local user.email ${BOT_EMAIL} git add changelog.md (git commit -m "🖉 Update changelog with ${GITHUB_REF#refs/*/}" && git push) || echo "Done" diff --git a/.github/workflows/defaults/action.yml b/.github/workflows/defaults/action.yml new file mode 100644 index 0000000..51ab461 --- /dev/null +++ b/.github/workflows/defaults/action.yml @@ -0,0 +1,65 @@ +name: test +description: runs dotnet tests with retry +runs: + using: "composite" + steps: + - name: 🔍 GH_TOKEN + if: env.GH_TOKEN == '' + shell: bash + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GH_TOKEN_SECRET: ${{ secrets.GH_TOKEN }} + run: | + if [ -z "${GH_TOKEN_SECRET}" ] + then + echo "Using default GITHUB_TOKEN" + echo "GH_TOKEN=${GITHUB_TOKEN}" >> $GITHUB_ENV + else + echo "Using custom GH_TOKEN" + echo "GH_TOKEN=${GH_TOKEN_SECRET}" >> $GITHUB_ENV + fi + + - name: 🔍 BOT_NAME + if: env.BOT_NAME == '' + shell: bash + env: + BOT_NAME_SECRET: ${{ secrets.BOT_NAME }} + run: | + if [ -z "${BOT_NAME_SECRET}" ] + then + echo "Using default GITHUB_AUTHOR as BOT_NAME" + echo "BOT_NAME=${GITHUB_AUTHOR}" >> $GITHUB_ENV + else + echo "Using custom BOT_NAME" + echo "BOT_NAME=${BOT_NAME_SECRET}" >> $GITHUB_ENV + fi + + - name: 🔍 BOT_EMAIL + if: env.BOT_EMAIL == '' + shell: bash + env: + BOT_EMAIL_SECRET: ${{ secrets.BOT_EMAIL }} + run: | + if [ -z "${BOT_EMAIL_SECRET}" ] + then + echo "Using default GITHUB_AUTHOR as BOT_EMAIL" + echo "BOT_EMAIL=${GITHUB_AUTHOR}@users.noreply.github.com" >> $GITHUB_ENV + else + echo "Using custom BOT_EMAIL" + echo "BOT_EMAIL=${BOT_EMAIL_SECRET}" >> $GITHUB_ENV + fi + + - name: 🔍 BOT_AUTHOR + if: env.BOT_AUTHOR == '' + shell: bash + env: + BOT_AUTHOR_SECRET: ${{ secrets.BOT_AUTHOR }} + run: | + if [ -z "${BOT_AUTHOR_SECRET}" ] + then + echo "Using default BOT_NAME <$BOT_EMAIL> as BOT_AUTHOR" + echo "BOT_AUTHOR=${BOT_NAME} <${BOT_EMAIL}>" >> $GITHUB_ENV + else + echo "Using custom BOT_AUTHOR" + echo "BOT_AUTHOR=${BOT_AUTHOR_SECRET}" >> $GITHUB_ENV + fi \ No newline at end of file diff --git a/.github/workflows/dotnet-file.yml b/.github/workflows/dotnet-file.yml index 81d3db2..51456c5 100644 --- a/.github/workflows/dotnet-file.yml +++ b/.github/workflows/dotnet-file.yml @@ -9,27 +9,13 @@ on: env: DOTNET_NOLOGO: true - GH_TOKEN: ${{ secrets.GH_TOKEN }} - BOT_AUTHOR: ${{ secrets.BOT_NAME }} <${{ secrets.BOT_EMAIL }}> jobs: sync: runs-on: windows-latest steps: - - name: 🔍 GH_TOKEN - if: env.GH_TOKEN == '' - shell: bash - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: echo "GH_TOKEN=${GITHUB_TOKEN}" >> $GITHUB_ENV - - - name: 🔍 BOT_AUTHOR - if: ${{ env.BOT_NAME == '' || env.BOT_EMAIL == '' }} - shell: bash - env: - BOT_NAME: ${{ secrets.BOT_NAME }} - BOT_EMAIL: ${{ secrets.BOT_EMAIL }} - run: echo "BOT_AUTHOR=${GITHUB_AUTHOR} <${GITHUB_AUTHOR}@users.noreply.github.com>" >> $GITHUB_ENV + - name: 🔍 defaults + uses: ./.github/workflows/defaults - name: ⌛ rate shell: pwsh @@ -79,10 +65,10 @@ jobs: branch: dotnet-file-sync delete-branch: true labels: dependencies + committer: ${{ env.BOT_AUTHOR }} commit-message: ⬆️ Bump files with dotnet-file sync ${{ env.CHANGES }} title: "⬆️ Bump files with dotnet-file sync" body: ${{ env.CHANGES }} - token: ${{ env.GH_TOKEN }} - author: ${{ env.BOT_AUTHOR }} + token: ${{ env.GH_TOKEN }} \ No newline at end of file diff --git a/.github/workflows/includes.yml b/.github/workflows/includes.yml index 230127e..31d3276 100644 --- a/.github/workflows/includes.yml +++ b/.github/workflows/includes.yml @@ -11,6 +11,9 @@ jobs: includes: runs-on: ubuntu-latest steps: + - name: 🔍 defaults + uses: ./.github/workflows/defaults + - name: 🤘 checkout uses: actions/checkout@v2 @@ -23,6 +26,9 @@ jobs: base: main branch: markdown-includes delete-branch: true + labels: dependencies + committer: ${{ env.BOT_AUTHOR }} commit-message: +M▼ includes title: +M▼ includes body: +M▼ includes + token: ${{ env.GH_TOKEN }} \ No newline at end of file