Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
auricom committed Sep 25, 2024
1 parent f7e1380 commit e3d32f7
Show file tree
Hide file tree
Showing 11 changed files with 247 additions and 106 deletions.
12 changes: 6 additions & 6 deletions .github/scripts/prepare-matrices.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ def get_app_metadata(subdir, meta, forRelease=False, channels=None):
# App Name
toBuild = {}
toBuild["name"] = meta["app"]
toBuild["channel"] = channel["name"]
toBuild["update_modules_enabled"] = channel["update_modules"]["enabled"]
toBuild["container_tag_name"] = channel["container_tag_name"]

toBuild["repository"] = meta["repository"]
toBuild["path"] = meta["path"]
toBuild["branch"] = channel["branch"]
toBuild["update_modules"] = channel["update_modules"]
toBuild["build_command"] = meta["build_command"]
toBuild["publish_artifacts"] = meta["publish_artifacts"]

# Container Tags
Expand All @@ -53,9 +55,6 @@ def get_app_metadata(subdir, meta, forRelease=False, channels=None):
# Platform Metadata
for platform in channel["platforms"]:

if platform not in TESTABLE_PLATFORMS and not forRelease:
continue

toBuild.setdefault("platforms", []).append(platform)

target_os = platform.split("/")[0]
Expand Down Expand Up @@ -86,9 +85,10 @@ def get_app_metadata(subdir, meta, forRelease=False, channels=None):
platformToBuild["tests_enabled"] = channel["tests"]["enabled"] and platform in TESTABLE_PLATFORMS
platformToBuild["tests_command"] = channel["tests"]["command"]

platformToBuild["build_command"] = toBuild["build_command"]
platformToBuild["publish_artifacts"] = meta["publish_artifacts"]
platformToBuild["update_modules"] = channel["update_modules"]
platformToBuild["update_modules_enabled"] = channel["update_modules"]["enabled"]
if channel["update_modules"]["enabled"]:
platformToBuild["update_modules_branch"] = channel["update_modules"]["cosmossdk_branch"]

appsToBuild["appsPlatforms"].append(platformToBuild)
appsToBuild["apps"].append(toBuild)
Expand Down
223 changes: 163 additions & 60 deletions .github/workflows/build-applications.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ on:
publishArtifacts:
required: false
type: boolean
default: false
default: true
sendNotifications:
required: false
default: false
Expand Down Expand Up @@ -64,8 +64,6 @@ jobs:
needs: prepare
runs-on: ubuntu-latest
if: ${{ toJSON(fromJSON(needs.prepare.outputs.matrices).appsPlatforms) != '[]' && toJSON(fromJSON(needs.prepare.outputs.matrices).appsPlatforms) != '' }}
outputs:
date: ${{ steps.archive.outputs.date }}
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -97,11 +95,11 @@ jobs:
check-latest: true

- name: Update go modules
if: ${{ matrix.app.update_modules }}
if: ${{ matrix.app.update_modules_enabled }}
run: |
set -x
cd ${{ matrix.app.repository }}/${{ matrix.app.path }}
COSMOSSDK_BRANCH=${{ matrix.app.branch }} ${{ github.workspace }}/nightly-stack/.github/scripts/update-go-modules.sh
COSMOSSDK_BRANCH=${{ matrix.app.update_modules_branch }} ${{ github.workspace }}/nightly-stack/.github/scripts/update-go-modules.sh
- name: show output of modified go.sum and go.mod
run: |
Expand All @@ -117,12 +115,10 @@ jobs:
- name: Create application binary
id: build
run: |
cd ${{ matrix.app.repository }}/${{ matrix.app.path }}
go mod tidy
cd ../
GOARCH=${{ matrix.app.target_arch }} ${{ matrix.app.build_command }}
echo "gobin=$(go env GOPATH)/bin" >> $GITHUB_OUTPUT
env:
MATRIX_APP_REPOSITORY: ${{ matrix.app.repository }}
MATRIX_APP_PATH: ${{ matrix.app.path }}
run: ./nightly-stack/apps/${{ matrix.app.name }}/ci/build.sh

- name: Run and monitor application
shell: bash
Expand All @@ -141,7 +137,7 @@ jobs:
TIMEOUT=60
START_TIME=$(date +%s)
cd ${{ matrix.app.repository }}/${{ matrix.app.path }}
cd ${{ matrix.app.repository }}
${{ matrix.app.tests_command }} > ./output.log 2>1 &
APP_PID=$!
Expand Down Expand Up @@ -170,53 +166,48 @@ jobs:
done
- name: Create archive
if: ${{ matrix.image.publish_artifacts }}
id: archive
if: ${{ matrix.app.publish_artifacts }}
run: |
set -oue pipefail
set -x
date=$(date +'%Y%m%d')
echo "date=$date" >> $GITHUB_ENV
echo "date=$date" >> $GITHUB_OUTPUT
# Create archive
BINARY_PATH=$(find $(go env GOPATH)/bin | tail -n 1)
mv $BINARY_PATH ${{ github.workspace }}/${{ matrix.app.name }}-${{ matrix.app.channel }}-$date-${{ matrix.app.target_arch }}
mv $BINARY_PATH ${{ github.workspace }}/${{ matrix.app.name }}-${{ matrix.app.channel }}-${{ matrix.app.target_os }}-${{ matrix.app.target_arch }}
- name: Upload Artifact
if: ${{ matrix.image.publish_artifacts }}
if: ${{ matrix.app.publish_artifacts }}
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.app.name }}-${{ matrix.app.channel }}-${{ env.date }}-${{ matrix.app.target_arch }}
path: ${{ github.workspace }}/${{ matrix.app.name }}-${{ matrix.app.channel }}-${{ env.date }}-${{ matrix.app.target_arch }}
name: ${{ matrix.app.name }}-${{ matrix.app.channel }}-${{ matrix.app.target_os }}-${{ matrix.app.target_arch }}
path: ${{ github.workspace }}/${{ matrix.app.name }}-${{ matrix.app.channel }}-${{ matrix.app.target_os }}-${{ matrix.app.target_arch }}
retention-days: 10

- name: Setup Docker Buildx
if: ${{ matrix.image.publish_artifacts }}
if: ${{ matrix.app.publish_artifacts }}
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
if: ${{ matrix.image.publish_artifacts }}
if: ${{ matrix.app.publish_artifacts }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: "${{ github.actor }}"
password: "${{ secrets.GITHUB_TOKEN }}"

- name: Setup Goss
if: ${{ matrix.go-arch == 'amd64' }}
if: ${{ matrix.app.tests_enabled }}
uses: e1himself/goss-installation-action@v1
with:
version: v0.4.4

- name: Lowercase repository owner
if: ${{ matrix.image.publish_artifacts }}
if: ${{ matrix.app.publish_artifacts }}
shell: bash
run: echo "LOWERCASE_REPO_OWNER=${GITHUB_REPOSITORY_OWNER,,}" >> "${GITHUB_ENV}"

- name: Prepare Build Outputs
if: ${{ matrix.image.publish_artifacts }}
if: ${{ matrix.app.publish_artifacts }}
id: prepare-build-outputs
shell: bash
run: |
Expand All @@ -227,38 +218,18 @@ jobs:
echo "outputs=${outputs}" >> $GITHUB_OUTPUT
- uses: actions/download-artifact@v4
if: ${{ matrix.image.publish_artifacts }}
if: ${{ matrix.app.publish_artifacts }}
with:
name: ${{ matrix.app.name }}-${{ matrix.app.channel }}-${{ env.date }}-${{ matrix.app.target_arch }}
path: nightly-stack/containers/cosmos-sdk

# - name: Build Image
# uses: docker/build-push-action@v6
# id: build-image
# with:
# build-args: |-
# BINARY=${{ matrix.app.name }}-${{ matrix.app.channel }}-${{ env.date }}-${{ matrix.app.target_arch }}
# context: ./nightly-stack/containers/cosmos-sdk
# file: ./nightly-stack/containers/cosmos-sdk/Dockerfile
# platforms: ${{ matrix.app.target_arch }}
# outputs: ${{ steps.prepare-build-outputs.outputs.outputs }}
# cache-from: type=gha
# cache-to: type=gha,mode=max
# labels: |-
# org.opencontainers.image.title=${{ steps.prepare-build-outputs.outputs.image_name }}
# org.opencontainers.image.url=https://ghcr.io/${{ env.LOWERCASE_REPO_OWNER }}/${{ steps.prepare-build-outputs.outputs.image_name }}
# org.opencontainers.image.source=https://github.com/${{ env.LOWERCASE_REPO_OWNER }}/containers
# org.opencontainers.image.version=${{ matrix.app.channel }}
# org.opencontainers.image.revision=${{ github.sha }}
# org.opencontainers.image.vendor=${{ env.LOWERCASE_REPO_OWNER }}
name: ${{ matrix.app.name }}-${{ matrix.app.channel }}-${{ matrix.app.target_os }}-${{ matrix.app.target_arch }}
path: nightly-stack/apps/${{ matrix.app.name}}

- name: Build Image
uses: docker/build-push-action@v6
id: build-image
if: ${{ matrix.image.publish_artifacts }}
if: ${{ matrix.app.publish_artifacts }}
with:
build-args: |-
BINARY=${{ matrix.app.name }}-${{ matrix.app.channel }}-${{ env.date }}-${{ matrix.app.target_arch }}
BINARY=${{ matrix.app.name }}-${{ matrix.app.channel }}-${{ matrix.app.target_os }}-${{ matrix.app.target_arch }}
context: ./nightly-stack/${{ matrix.app.context }}
file: ./nightly-stack/${{ matrix.app.dockerfile }}
platforms: ${{ matrix.app.target_arch }}
Expand All @@ -275,23 +246,23 @@ jobs:
- name: Run Goss Tests
id: dgoss
if: ${{ matrix.image.tests_enabled && matrix.image.publish_artifacts }}
if: ${{ matrix.app.tests_enabled }}
env:
CONTAINER_RUNTIME: docker
GOSS_FILES_PATH: ${{ github.workspace }}/nightly-stack/containers/cosmos-sdk/ci
GOSS_FILE: ./nightly-stack/${{ matrix.app.goss_config }}
GOSS_OPTS: --retry-timeout 60s --sleep 2s --color --format documentation
GOSS_SLEEP: 2
GOSS_FILES_STRATEGY: cp
CONTAINER_LOG_OUTPUT: goss_container_log_output
shell: bash
run: |
set -x
ls -l ${{ github.workspace }}/nightly-stack/containers/cosmos-sdk/ci/goss.yaml
ls -l ./nightly-stack/${{ matrix.app.goss_config }}
image_name="${{ steps.prepare-build-outputs.outputs.image_name }}@${{ steps.build-image.outputs.digest }}"
dgoss run ${image_name}
dgoss.sh run ${image_name}
- name: Export Digest
if: ${{ matrix.image.publish_artifacts }}
if: ${{ matrix.app.publish_artifacts }}
id: export-digest
shell: bash
run: |
Expand All @@ -300,10 +271,142 @@ jobs:
echo "${{ matrix.app.name }}" > "/tmp/${{ matrix.app.name }}/digests/${digest#sha256:}"
- name: Upload Digest
if: ${{ matrix.image.publish_artifacts }}
if: ${{ matrix.app.publish_artifacts }}
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.app.name }}-${{ matrix.app.channel }}-${{ matrix.app.target_arch }}
name: digest-${{ matrix.app.name }}-${{ matrix.app.channel }}-${{ matrix.app.target_os }}-${{ matrix.app.target_arch }}
path: /tmp/${{ matrix.app.name }}/*
if-no-files-found: error
retention-days: 1
retention-days: 1

merge:
name: Merge ${{ matrix.app.name }} ${{ matrix.app.channel }}
runs-on: ubuntu-latest
needs: ["prepare", "build-platform-app"]
# Always run merge, as the prior matrix is all or nothing. We test for prior step failure
# in the "Test Failed Bit" step. This ensures if one app fails, others can still complete.
# if: ${{ always() && inputs.pushArtifacts && toJSON(fromJSON(needs.prepare.outputs.matrices).apps) != '[]' && toJSON(fromJSON(needs.prepare.outputs.matrices).apps) != '' }}
if: ${{ always() }}
strategy:
matrix:
app: "${{ fromJSON(needs.prepare.outputs.matrices).apps }}"
fail-fast: false
steps:
- name: Log Matrix Input
shell: bash
run: |
cat << EOF
${{ toJSON(matrix.app)}}
EOF
- name: Set variables
id: variables
shell: bash
run: |
set -x
echo "LOWERCASE_REPO_OWNER=${GITHUB_REPOSITORY_OWNER,,}" >> $GITHUB_ENV
- name: Download Digests
uses: actions/download-artifact@v4
with:
pattern: "digest-${{ matrix.app.name }}-${{ matrix.app.channel }}-{linux,darwin}-{amd64,arm64}"
merge-multiple: true
path: /tmp/${{ matrix.app.name }}

- name: Ensure all platforms were built
id: ensure-platforms
shell: bash
run: |
EXPECTED_COUNT=$(cat << EOF | jq ". | length"
${{ toJSON(matrix.app.platforms) }}
EOF
)
ACTUAL_COUNT=$(ls -1 /tmp/${{ matrix.app.name }}/digests | wc -l)
if [[ $EXPECTED_COUNT != $ACTUAL_COUNT ]]; then
echo "Expected $EXPECTED_COUNT platforms, but only found $ACTUAL_COUNT"
echo "Expected: ${{ toJSON(matrix.app.platforms) }}"
echo "Actual: $(cat /tmp/${{ matrix.app.name }}/digests/*)"
exit 1
fi
- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: "${{ github.actor }}"
password: "${{ secrets.GITHUB_TOKEN }}"

- name: Log Files
working-directory: /tmp/${{ matrix.app.name }}/digests
shell: bash
run: |
ls -la
cat *
- name: Merge Manifests
id: merge
working-directory: /tmp/${{ matrix.app.name }}/digests
shell: bash
run: |
set -x
docker buildx imagetools create \
--tag ghcr.io/${{ env.LOWERCASE_REPO_OWNER }}/${{ matrix.app.name }}:${{ matrix.app.container_tag_name }} \
$(printf 'ghcr.io/${{ env.LOWERCASE_REPO_OWNER }}/${{ matrix.app.name }}@sha256:%s ' *)
- name: Inspect image
id: inspect
shell: bashcurl https://get.ignite.com/cli! | bash
run: |
docker buildx imagetools inspect ghcr.io/${{ env.LOWERCASE_REPO_OWNER }}/${{ matrix.app.name }}:${{ matrix.app.container_tag_name }}
- name: Build successful
id: build-success
if: ${{ always() && steps.merge.outcome == 'success' && steps.inspect.outcome == 'success' }}
shell: bash
run: |
echo "slack_message=🎉 Nightly build ${{ matrix.app.name }} (${{ matrix.app.channel }})" >> $GITHUB_OUTPUT
echo "slack_color=good" >> $GITHUB_OUTPUT
echo "slack_icon_emoji=:white_check_mark:" >> $GITHUB_OUTPUT
- name: Build failed
id: build-failed
if: ${{ always() && (steps.merge.outcome == 'failure' || steps.inspect.outcome == 'failure') }}
shell: bash
run: |
echo "slack_message=💥 Nightly build ${{ matrix.app.name }} (${{ matrix.app.channel }})" >> $GITHUB_OUTPUT
echo "slack_color=danger" >> $GITHUB_OUTcurl https://get.ignite.com/cli! | bashPUT
echo "slack_icon_emoji=:skull:" >> $GITHUB_OUTPUT
- name: Get previous workflow status
uses: cosmos/cosmos-sdk/.github/actions/last-workflow-status@main
id: last_status
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Notify Slack
if: ${{ always() && inputs.sendNotifications == 'true' }}
uses: rtCamp/action-slack-notify@v2.3.0
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_CHANNEL: nightly-stack-build
SLACK_USERNAME: Nightly Builds
SLACK_ICON_EMOJI: ${{ steps.build-failed.outputs.slack_icon_emoji || steps.build-success.outputs.slack_icon_emoji }}
SLACK_COLOR: ${{ steps.build-failed.outputs.slack_color || steps.build-success.outputs.slack_color }}
SLACK_MESSAGE: ${{ steps.build-failed.outputs.slack_message || steps.build-success.outputs.slack_message }}
SLACK_FOOTER: ""


# Summarize matrix https://gh.neting.ccmunity/t/status-check-for-a-matrix-jobs/127354/7
build_success:
name: Build matrix success
runs-on: ubuntu-latest
needs: ["prepare", "merge"]
if: ${{ always() }}
steps:
- name: Check build matrix status
if: ${{ (inputs.appsToBuild != '' && inputs.appsToBuild != '[]') && (needs.merge.result != 'success' && needs.merge.result != 'skipped' && needs.prepare.result != 'success') }}
shell: bash
run: exit 1
1 change: 1 addition & 0 deletions .github/workflows/nightlies-scheduled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
with:
# appsToBuild: ${{ inputs.appsToBuild }}
appsToBuild: all
publishArtifacts: true
sendNotifications: true

# render-readme:
Expand Down
Loading

0 comments on commit e3d32f7

Please sign in to comment.