Skip to content

Commit

Permalink
refactor(workflows): migrate report after build (#199)
Browse files Browse the repository at this point in the history
This pull request includes significant changes to the GitHub Actions
workflows, particularly focusing on the build, continuous integration
(CI), and continuous deployment (CD) processes. The main changes involve
updating input parameters, modifying job strategies, and restructuring
the workflows to improve efficiency and clarity.

### Workflow Updates:

* **Build Workflow:**
* Updated input parameters to include `context`, `environment`, and
`image` instead of `images`. (`.github/workflows/build.yml`)
* Removed the matrix strategy and directly used input parameters for the
environment and image. (`.github/workflows/build.yml`)
* Adjusted Docker metadata-action and build-test steps to use
`inputs.image` and `inputs.context`. (`.github/workflows/build.yml`)
[[1]](diffhunk://#diff-5c3fa597431eda03ac3339ae6bf7f05e1a50d6fc7333679ec38e21b337cb6721L66-R61)
[[2]](diffhunk://#diff-5c3fa597431eda03ac3339ae6bf7f05e1a50d6fc7333679ec38e21b337cb6721L101-R112)
[[3]](diffhunk://#diff-5c3fa597431eda03ac3339ae6bf7f05e1a50d6fc7333679ec38e21b337cb6721L127-R122)
[[4]](diffhunk://#diff-5c3fa597431eda03ac3339ae6bf7f05e1a50d6fc7333679ec38e21b337cb6721L156-R192)

* **Continuous Deployment (CD) Workflow:**
* Reintroduced the matrix strategy to handle multiple images and
contexts. (`.github/workflows/cd.yml`)

* **Continuous Integration (CI) Workflow:**
* Adjusted the outputs and reintroduced the matrix strategy for handling
multiple images and contexts. (`.github/workflows/ci.yml`)
[[1]](diffhunk://#diff-b803fcb7f17ed9235f1e5cb1fcd2f5d3b2838429d4368ae4c57ce4436577f03fL24-R24)
[[2]](diffhunk://#diff-b803fcb7f17ed9235f1e5cb1fcd2f5d3b2838429d4368ae4c57ce4436577f03fL38-R51)
[[3]](diffhunk://#diff-b803fcb7f17ed9235f1e5cb1fcd2f5d3b2838429d4368ae4c57ce4436577f03fL48-R61)

* **Report Workflow:**
* Removed the `report.yml` workflow and integrated its functionality
directly into the build workflow. (`.github/workflows/report.yml`)
  • Loading branch information
0x1026 authored Dec 11, 2024
2 parents 41d46d7 + 0326394 commit 20eb394
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 100 deletions.
76 changes: 55 additions & 21 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ name: 🏗️ Build
on:
workflow_call:
inputs:
images:
default: '["all"]'
context:
required: true
type: string
environment:
default: test
type: string
image:
required: true
type: string
version:
type: string
Expand All @@ -24,18 +30,7 @@ jobs:
build:
name: 🐳 Docker
runs-on: ubuntu-latest
strategy:
fail-fast: false
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/running-variations-of-jobs-in-a-workflow#example-adding-configurations
matrix:
image: ${{ fromJSON(inputs.images) }}
exclude:
- image: all
include:
- image: urbantree
context: ./app
- image: api
context: ./api
environment: ${{ inputs.image }}-test

steps:
# https://github.com/actions/checkout/tree/11bd71901bbe5b1630ceea73d27597364c9af683
Expand Down Expand Up @@ -63,7 +58,7 @@ jobs:
- uses: docker/metadata-action@b53be03109c4ef6f6cc7aa545b84b17a7fe51c1e
id: meta
with:
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ matrix.image }}
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ inputs.image }}
tags: |
type=ref,event=branch
type=semver,pattern={{version}},value=${{ inputs.version }}
Expand Down Expand Up @@ -98,23 +93,23 @@ jobs:
id: build-test
with:
load: true
context: ${{ matrix.context }}
context: ${{ inputs.context }}
target: test
cache-from: type=gha
cache-to: type=gha,mode=max
env:
APP_ENV: test

- name: 🧪 Run tests
run: docker run --rm -v "$(pwd)/reports/${{ matrix.image }}:/reports" ${{ steps.build-test.outputs.imageid }}
run: docker run --rm -v "$(pwd)/reports/${{ inputs.image }}:/reports" ${{ steps.build-test.outputs.imageid }}

# https://github.com/actions/upload-artifact/tree/b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
- name: 📤 Upload coverage data
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
if: ${{ !cancelled() }}
with:
name: ${{ matrix.image }}-coverage
path: reports/${{ matrix.image }}
name: ${{ inputs.image }}-coverage
path: reports/${{ inputs.image }}
retention-days: 1

# https://github.com/docker/build-push-action/tree/48aba3b46d1b1fec4febb7c5d0c644b249a11355
Expand All @@ -124,7 +119,7 @@ jobs:
with:
build-args: |
IMAGE_VERSION=${{ inputs.version }}
context: ${{ matrix.context }}
context: ${{ inputs.context }}
push: ${{ !!inputs.version }}
target: final
tags: ${{ steps.meta.outputs.tags }}
Expand Down Expand Up @@ -153,6 +148,45 @@ jobs:
uses: actions/attest-build-provenance@7668571508540a607bdfd90a87a560489fe372eb
if: inputs.version
with:
subject-name: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ matrix.image }}
subject-name: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ inputs.image }}
subject-digest: ${{ steps.build-and-push.outputs.digest }}
push-to-registry: true

report:
name: 🗂️ Upload reports
needs: build
runs-on: ubuntu-latest
if: ${{ !cancelled() }}

steps:
# https://github.com/actions/checkout/tree/11bd71901bbe5b1630ceea73d27597364c9af683
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683

# https://github.com/actions/download-artifact/tree/fa0a91b85d4f404e444e00e005971372dc801d16
- name: 📥 Download coverage data
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
with:
name: ${{ inputs.image }}-coverage

# https://github.com/getsentry/action-release/tree/e769183448303de84c5a06aaaddf9da7be26d6c7
- name: 📟 Release to Sentry
uses: ./.github/actions/release-sentry
with:
environment: ${{ inputs.environment }}
projects: ${{ inputs.image }}
version: ${{ inputs.version || github.sha }}
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: ${{ secrets.SENTRY_ORG }}

# https://github.com/codecov/test-results-action/tree/9739113ad922ea0a9abb4b2c0f8bf6a4aa8ef820
- name: 🧮 Upload test results to Codecov
uses: codecov/test-results-action@9739113ad922ea0a9abb4b2c0f8bf6a4aa8ef820
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

# https://github.com/codecov/codecov-action/tree/7f8b4b4bde536c465e797be725718b88c5d95e0e
- name: 📈 Upload coverage to Codecov
uses: codecov/codecov-action@7f8b4b4bde536c465e797be725718b88c5d95e0e
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
21 changes: 12 additions & 9 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,25 @@ jobs:
name: 🏗️ Build
needs: foundation
uses: ./.github/workflows/build.yml
strategy:
fail-fast: false
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/running-variations-of-jobs-in-a-workflow#example-adding-configurations
matrix:
include:
- image: urbantree
context: ./app
- image: api
context: ./api
permissions:
contents: read
packages: write
attestations: write
id-token: write
with:
context: ${{ matrix.context }}
environment: ${{ needs.foundation.outputs.version && 'production' }}
image: ${{ matrix.image }}
version: ${{ needs.foundation.outputs.version }}

report:
name: 🗃️ Report
needs: build
if: ${{ !cancelled() }}
uses: ./.github/workflows/report.yml
with:
environment: ${{ needs.build.outputs.version && 'production' }}
version: ${{ needs.build.outputs.version }}
secrets: inherit

release:
Expand Down
27 changes: 16 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
permissions:
pull-requests: read
outputs:
images: ${{ github.event_name == 'push' && '["all"]' || steps.filter.outputs.changes }}
images: ${{ contains(steps.filter.outputs.changes, '[]') && '["all"]' || steps.filter.outputs.changes }}
steps:
# https://github.com/actions/checkout/tree/11bd71901bbe5b1630ceea73d27597364c9af683
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
Expand All @@ -35,8 +35,20 @@ jobs:

build:
name: 🏗️ Build
needs: [foundation]
needs: foundation
uses: ./.github/workflows/build.yml
strategy:
fail-fast: false
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/running-variations-of-jobs-in-a-workflow#example-adding-configurations
matrix:
image: ${{ fromJson(needs.foundation.outputs.images) }}
exclude:
- image: all
include:
- image: urbantree
context: ./app
- image: api
context: ./api
permissions:
contents: read
packages: write
Expand All @@ -45,13 +57,6 @@ jobs:
# with sigstore/fulcio when running outside of PRs.
id-token: write
with:
images: ${{ needs.foundation.outputs.images }}

report:
name: 🗃️ Report
needs: [build]
if: ${{ !cancelled() }}
uses: ./.github/workflows/report.yml
with:
version: ${{ github.sha }}
context: ${{ matrix.context }}
image: ${{ matrix.image }}
secrets: inherit
59 changes: 0 additions & 59 deletions .github/workflows/report.yml

This file was deleted.

0 comments on commit 20eb394

Please sign in to comment.