From 222cb91705a31186dceefb4753579240e73b1091 Mon Sep 17 00:00:00 2001 From: Kasey Kirkham Date: Tue, 7 Jan 2025 17:01:48 -0600 Subject: [PATCH] modular action workflow --- .github/workflows/build-unclog.yml | 57 ++++++++++++++++++++++++++++++ .github/workflows/changelog.yml | 47 +++--------------------- .github/workflows/dogfood.yml | 48 +++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 43 deletions(-) create mode 100644 .github/workflows/build-unclog.yml create mode 100644 .github/workflows/dogfood.yml diff --git a/.github/workflows/build-unclog.yml b/.github/workflows/build-unclog.yml new file mode 100644 index 0000000..ebbadfb --- /dev/null +++ b/.github/workflows/build-unclog.yml @@ -0,0 +1,57 @@ +name: build-unclog + +on: + workflow_call: + inputs: + artifact-name: + required: false + type: string + outputs: + artifact-name: + description: "name of uploaded artifact" + value: ${{ jobs.build_unclog.outputs.artifact-name}} + +jobs: + build-unclog: + runs-on: ubuntu-latest + outputs: + artifact-name: ${{ steps.artifact-namer.outputs.artifact-name }} + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.22' + + - name: Build + run: go build -o unclog -v . + + - name: Default binary name + if: ${{ inputs.artifact-name != '' }} + shell: bash + run: | + echo "UNCLOG_BINARY_NAME={{ $inputs.artifact-name }}" >> ${GITHUB_ENV} + + - name: Scoped name in PR + if: ${{ inputs.artifact-name == '' && github.event_name == 'pull_request' }} + shell: bash + run: | + echo "UNCLOG_BINARY_NAME=unclog-${{ github.event.pull_request.head.sha }}" >> ${GITHUB_ENV} + - name: Scoped name on push + if: ${{ inputs.artifact-name == '' && github.event_name == 'push' }} + shell: bash + run: | + echo "UNCLOG_BINARY_NAME=unclog-${GITHUB_SHA}" >> ${GITHUB_ENV} + + - name: Set artifact-name output parameter + id: artifact-namer + shell: bash + run: | + echo "artifact-name=${UNCLOG_BINARY_NAME}" >> "$GITHUB_OUTPUT" + + - name: Upload unclog binary + uses: actions/upload-artifact@v4 + with: + name: ${{ steps.artifact-namer.outputs.artifact-name}} + path: unclog diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml index 97fd2a2..3775397 100644 --- a/.github/workflows/changelog.yml +++ b/.github/workflows/changelog.yml @@ -1,7 +1,7 @@ # This workflow will build a golang project # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go -name: build-unclog +name: main-artifact-refresher on: pull_request: @@ -12,45 +12,6 @@ on: jobs: build-changelog-check: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: '1.22' - - - name: Build - run: go build -o unclog -v . - - - name: Upload changelog binary - uses: actions/upload-artifact@v3 - with: - name: unclog-binary - path: unclog - - run-changelog-check: - runs-on: ubuntu-latest - needs: build-changelog-check - - steps: - - name: Checkout source code - uses: actions/checkout@v3 - - - name: Download changelog check binary - uses: actions/download-artifact@v3 - with: - name: unclog-binary - - - name: Get new changelog files - id: new-changelog-files - uses: tj-actions/changed-files@v45 - with: - files: | - log/**.md - - - name: Run lint command - env: - ALL_ADDED_MARKDOWN: ${{ steps.new-changelog-files.outputs.added_files }} - run: chmod +x unclog && ./unclog check -fragment-env=ALL_ADDED_MARKDOWN + uses: ./.github/workflows/build-unclog.yml + with: + artifact-name: unclog diff --git a/.github/workflows/dogfood.yml b/.github/workflows/dogfood.yml new file mode 100644 index 0000000..dd7532a --- /dev/null +++ b/.github/workflows/dogfood.yml @@ -0,0 +1,48 @@ +# This workflow will build a golang project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go + +name: dogfood + +on: + pull_request: + branches: [ "main" ] + +jobs: + build-unclog: + outputs: + artifact-name: ${{ steps.unclog-build.outputs.artifact-name }} + steps: + + - name: Run unclog build + id: unclog-build + uses: ./.github/workflows/build-unclog.yml + + run-changelog-check: + runs-on: ubuntu-latest + needs: build-unclog + + steps: + + - name: Download changelog check binary + id: unclog-download + uses: actions/download-artifact@v4 + with: + name: ${{ needs.build-unclog.outputs.artifact-name }} + + - name: Checkout source code + uses: actions/checkout@v4 + + - name: Get new changelog files + id: new-changelog-files + uses: tj-actions/changed-files@v45 + with: + files: | + log/**.md + + - name: Run lint command + shell: bash + env: + ALL_ADDED_MARKDOWN: ${{ steps.new-changelog-files.outputs.added_files }} + UNCLOG_BIN: ${{ steps.unclog-download.outputs.download-path}}/${{ needs.build-unclog.outputs-artifact-name }} + run: | + chmod +x ${UNCLOG_BIN} && ./${UNCLOG_BIN} check -fragment-env=ALL_ADDED_MARKDOWN