From 40e6376dce939479a958baeda255ec00152e79da Mon Sep 17 00:00:00 2001 From: Kasey Kirkham Date: Tue, 7 Jan 2025 16:33:13 -0600 Subject: [PATCH 1/6] set up workflow to support external repo use --- .../{changelog-check.yml => changelog.yml} | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) rename .github/workflows/{changelog-check.yml => changelog.yml} (83%) diff --git a/.github/workflows/changelog-check.yml b/.github/workflows/changelog.yml similarity index 83% rename from .github/workflows/changelog-check.yml rename to .github/workflows/changelog.yml index 4ce87b0..97fd2a2 100644 --- a/.github/workflows/changelog-check.yml +++ b/.github/workflows/changelog.yml @@ -1,11 +1,14 @@ # 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: changelog-check +name: build-unclog on: pull_request: - branches: [ "main" ] + types: + - closed + schedule: + - cron: "0 0 1 * *" # run at least monthly due to 90 day artifact retention jobs: build-changelog-check: @@ -21,10 +24,10 @@ jobs: - name: Build run: go build -o unclog -v . - - name: Upload linter binary + - name: Upload changelog binary uses: actions/upload-artifact@v3 with: - name: changelog-check-binary + name: unclog-binary path: unclog run-changelog-check: @@ -38,7 +41,7 @@ jobs: - name: Download changelog check binary uses: actions/download-artifact@v3 with: - name: changelog-check-binary + name: unclog-binary - name: Get new changelog files id: new-changelog-files From 66fe56ba589a983134cd749e9eca5eceb32dcddc Mon Sep 17 00:00:00 2001 From: Kasey Kirkham Date: Tue, 7 Jan 2025 17:01:48 -0600 Subject: [PATCH 2/6] modular action workflow --- .github/workflows/build-unclog.yml | 57 ++++++++++++++++++++++++++++++ .github/workflows/changelog.yml | 47 +++--------------------- .github/workflows/dogfood.yml | 49 +++++++++++++++++++++++++ 3 files changed, 110 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..194cf63 --- /dev/null +++ b/.github/workflows/dogfood.yml @@ -0,0 +1,49 @@ +# 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: + runs-on: ubuntu-latest + 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 From 3cde30b9170d4f9bbad3c76d0fc534eb15df8ac5 Mon Sep 17 00:00:00 2001 From: Kasey Kirkham Date: Wed, 8 Jan 2025 13:17:47 -0600 Subject: [PATCH 3/6] use composite action for output plumbing --- .github/actions/build-unclog/action.yml | 54 +++++++++++++++++++++++ .github/workflows/build-unclog.yml | 57 ------------------------- .github/workflows/dogfood.yml | 17 +++++--- 3 files changed, 65 insertions(+), 63 deletions(-) create mode 100644 .github/actions/build-unclog/action.yml delete mode 100644 .github/workflows/build-unclog.yml diff --git a/.github/actions/build-unclog/action.yml b/.github/actions/build-unclog/action.yml new file mode 100644 index 0000000..3c4cf9b --- /dev/null +++ b/.github/actions/build-unclog/action.yml @@ -0,0 +1,54 @@ +name: build-unclog +description: builds the unclog binary from source + +inputs: + artifact-name: + required: false + type: string +outputs: + artifact-name: + description: "name of uploaded artifact" + value: ${{ steps.artifact-namer.outputs.artifact-name }} + +runs: + using: "composite" + steps: + - uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.22' + + - name: Build + shell: bash + 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/build-unclog.yml b/.github/workflows/build-unclog.yml deleted file mode 100644 index ebbadfb..0000000 --- a/.github/workflows/build-unclog.yml +++ /dev/null @@ -1,57 +0,0 @@ -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/dogfood.yml b/.github/workflows/dogfood.yml index 194cf63..4679692 100644 --- a/.github/workflows/dogfood.yml +++ b/.github/workflows/dogfood.yml @@ -14,25 +14,27 @@ jobs: artifact-name: ${{ steps.unclog-build.outputs.artifact-name }} steps: + - name: Checkout source code + uses: actions/checkout@v4 + - name: Run unclog build id: unclog-build - uses: ./.github/workflows/build-unclog.yml + uses: ./.github/actions/build-unclog run-changelog-check: runs-on: ubuntu-latest needs: build-unclog - steps: + - name: Checkout source code + uses: actions/checkout@v4 + - 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 @@ -45,5 +47,8 @@ jobs: 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 }} + UNCLOG_BIN_DIR: ${{ steps.unclog-download.outputs.download-path}} + UNCLOG_BIN_FNAME: ${{ needs.build-unclog.outputs-artifact-name }} run: | - chmod +x ${UNCLOG_BIN} && ./${UNCLOG_BIN} check -fragment-env=ALL_ADDED_MARKDOWN + echo "UNCLOG_BIN=${UNCLOG_BIN}, UNCLOG_BIN_DIR=${UNCLOG_BIN_DIR}, UNCLOG_BIN_FNAME=${UNCLOG_BIN_FNAME}" + #chmod +x ${UNCLOG_BIN} && ./${UNCLOG_BIN} check -fragment-env=ALL_ADDED_MARKDOWN From 553e2c769967ad6660d37fe0cc1b31ff55020e29 Mon Sep 17 00:00:00 2001 From: Kasey Kirkham Date: Wed, 8 Jan 2025 15:02:09 -0600 Subject: [PATCH 4/6] build inline --- .github/workflows/dogfood.yml | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/.github/workflows/dogfood.yml b/.github/workflows/dogfood.yml index 4679692..b2ff8ea 100644 --- a/.github/workflows/dogfood.yml +++ b/.github/workflows/dogfood.yml @@ -8,32 +8,21 @@ on: branches: [ "main" ] jobs: - build-unclog: - runs-on: ubuntu-latest - outputs: - artifact-name: ${{ steps.unclog-build.outputs.artifact-name }} - steps: - - - name: Checkout source code - uses: actions/checkout@v4 - - - name: Run unclog build - id: unclog-build - uses: ./.github/actions/build-unclog - run-changelog-check: runs-on: ubuntu-latest - needs: build-unclog steps: - - name: Checkout source code uses: actions/checkout@v4 + - name: build-unclog + id: unclog-build + uses: ./.github/actions/build-unclog + - name: Download changelog check binary id: unclog-download uses: actions/download-artifact@v4 with: - name: ${{ needs.build-unclog.outputs.artifact-name }} + name: ${{ steps.unclog-build.outputs.artifact-name }} - name: Get new changelog files id: new-changelog-files @@ -46,9 +35,7 @@ jobs: 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 }} - UNCLOG_BIN_DIR: ${{ steps.unclog-download.outputs.download-path}} - UNCLOG_BIN_FNAME: ${{ needs.build-unclog.outputs-artifact-name }} + #UNCLOG_BIN: ${{ steps.unclog-download.outputs.download-path}}/${{ steps.unclog-build.outputs.artifact-name }} + #UNCLOG_DIR: ${{ steps.unclog-download.outputs.download-path}} run: | - echo "UNCLOG_BIN=${UNCLOG_BIN}, UNCLOG_BIN_DIR=${UNCLOG_BIN_DIR}, UNCLOG_BIN_FNAME=${UNCLOG_BIN_FNAME}" - #chmod +x ${UNCLOG_BIN} && ./${UNCLOG_BIN} check -fragment-env=ALL_ADDED_MARKDOWN + chmod +x unclog && ./unclog check -fragment-env=ALL_ADDED_MARKDOWN From 7f5cc9467f6059ee9008831e4357efb520a93add Mon Sep 17 00:00:00 2001 From: Kasey Kirkham Date: Wed, 8 Jan 2025 15:14:35 -0600 Subject: [PATCH 5/6] add changelog fragment to satisfy check --- log/kasey_test-build-action.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 log/kasey_test-build-action.md diff --git a/log/kasey_test-build-action.md b/log/kasey_test-build-action.md new file mode 100644 index 0000000..4e97d33 --- /dev/null +++ b/log/kasey_test-build-action.md @@ -0,0 +1,3 @@ +### Changed + +- refactored github actions to be composable between local workflow testing and artifact "release" From 56256178a53c74fe0e9514ce59e5ede84cf82898 Mon Sep 17 00:00:00 2001 From: Kasey Kirkham Date: Wed, 8 Jan 2025 15:24:47 -0600 Subject: [PATCH 6/6] update main refresh workflow to use composite action --- .github/actions/build-unclog/action.yml | 2 -- .github/workflows/changelog.yml | 17 ----------------- .github/workflows/main-artifact-refresh.yml | 21 +++++++++++++++++++++ 3 files changed, 21 insertions(+), 19 deletions(-) delete mode 100644 .github/workflows/changelog.yml create mode 100644 .github/workflows/main-artifact-refresh.yml diff --git a/.github/actions/build-unclog/action.yml b/.github/actions/build-unclog/action.yml index 3c4cf9b..f392959 100644 --- a/.github/actions/build-unclog/action.yml +++ b/.github/actions/build-unclog/action.yml @@ -13,8 +13,6 @@ outputs: runs: using: "composite" steps: - - uses: actions/checkout@v4 - - name: Set up Go uses: actions/setup-go@v5 with: diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml deleted file mode 100644 index 3775397..0000000 --- a/.github/workflows/changelog.yml +++ /dev/null @@ -1,17 +0,0 @@ -# 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: main-artifact-refresher - -on: - pull_request: - types: - - closed - schedule: - - cron: "0 0 1 * *" # run at least monthly due to 90 day artifact retention - -jobs: - build-changelog-check: - uses: ./.github/workflows/build-unclog.yml - with: - artifact-name: unclog diff --git a/.github/workflows/main-artifact-refresh.yml b/.github/workflows/main-artifact-refresh.yml new file mode 100644 index 0000000..09fda0e --- /dev/null +++ b/.github/workflows/main-artifact-refresh.yml @@ -0,0 +1,21 @@ +name: main-artifact-refresh +description: "ensures there is always an unclog artifact available, building monthly (less than 90 day retention period) or when PRs merge to main" + +on: + pull_request: + types: + - closed + schedule: + - cron: "0 0 1 * *" # run first day of month + +jobs: + refresh-unclog-binary: + runs-on: ubuntu-latest + steps: + - name: Checkout source code + uses: actions/checkout@v4 + + - name: build-unclog + uses: ./.github/actions/build-unclog + with: + artifact-name: unclog # This is the 'release' artifact name