-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
26147ce
commit 9b3b145
Showing
4 changed files
with
128 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
name: ci/cd | ||
|
||
on: | ||
push: | ||
pull_request: | ||
workflow_dispatch: | ||
schedule: | ||
- cron: '0 0 1 * *' # monthly container rebuild | ||
- cron: '0 6 * * 6' # weekly integration tests | ||
|
||
jobs: | ||
test: | ||
if: github.event_name != 'schedule' || github.event.schedule != '0 0 1 * *' | ||
runs-on: ubuntu-latest | ||
outputs: | ||
coverage-percentage: ${{ steps.percentage.outputs.percentage }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Lint and test in container | ||
run: podman build --tag tests-${{ github.event.repository.name }}:latest --target test . | ||
- name: Output coverage percentage | ||
id: percentage | ||
run: echo "percentage=$(podman run --rm tests-${{ github.event.repository.name }}:latest json -o - | jq '.totals.percent_covered_display')" >> $GITHUB_OUTPUT | ||
- name: Save coverage report | ||
run: podman run --rm tests-${{ github.event.repository.name }}:latest report --format=markdown >> $GITHUB_STEP_SUMMARY | ||
|
||
integration: | ||
if: secrets.TESTS_BOT_USERNAME != '' && (github.event_name != 'schedule' || github.event.schedule == '0 0 1 * *') | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Run integration tests | ||
run: podman build --env USERNAME --env PASSWORD --env TESTS_MOD_USERNAME --env TESTS_MOD_PASSWORD --target integration . | ||
env: | ||
USERNAME: ${{ secrets.TESTS_BOT_USERNAME }} | ||
PASSWORD: ${{ secrets.TESTS_BOT_PASSWORD }} | ||
TESTS_MOD_USERNAME: ${{ secrets.TESTS_MOD_USERNAME }} | ||
TESTS_MOD_PASSWORD: ${{ secrets.TESTS_MOD_PASSWORD }} | ||
|
||
coverage-badge: | ||
runs-on: ubuntu-latest | ||
needs: test | ||
if: github.event_name == 'push' && github.ref_name == 'main' | ||
permissions: | ||
contents: write | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
ref: "coverage-badge" | ||
- name: Calculate badge color | ||
id: color | ||
run: | | ||
echo "color=$(python3 -Ic 'print( | ||
min( | ||
(percentage, color) | ||
for percentage, color in [ | ||
(100, "brightgreen"), | ||
(90, "green"), | ||
(70, "yellowgreen"), | ||
(50, "yellow"), | ||
(30, "orange"), | ||
(0, "red"), | ||
] | ||
if percentage >= int(${{ needs.test.outputs.coverage-percentage }}) | ||
)[1] | ||
)')" >> $GITHUB_OUTPUT | ||
- name: Update JSON file | ||
run: | | ||
jq -n \ | ||
--argjson schemaVersion 1 \ | ||
--arg label coverage \ | ||
--arg message ${{ needs.test.outputs.coverage-percentage }}% \ | ||
--arg color ${{ steps.color.outputs.color }} \ | ||
'$ARGS.named' > coverage-badge.json | ||
- name: Create commit | ||
run: | | ||
git config user.name 'prns' | ||
git config user.email '[email protected]' | ||
git commit -am "Update coverage" && git push || true | ||
publish: | ||
permissions: | ||
contents: read | ||
packages: write | ||
needs: test | ||
if: contains(fromJSON('["push", "workflow_dispatch", "schedule"]'), github.event_name) && github.ref_name == 'main' | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Get target image name | ||
id: image | ||
run: echo "image_name=${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT | ||
- name: Build image | ||
run: podman build --tag ${{ steps.image.outputs.image_name }}:latest . | ||
- name: Push to ghcr.io | ||
run: podman push --creds=${{ github.actor }}:${{ github.token }} ${{ steps.image.outputs.image_name }}:latest ghcr.io/${{ steps.image.outputs.image_name }}:latest | ||
- name: Delete old image versions | ||
uses: actions/delete-package-versions@v5 | ||
with: | ||
package-name: ${{ github.event.repository.name }} | ||
package-type: container | ||
min-versions-to-keep: 10 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters