|
| 1 | +name: publish release |
| 2 | + |
| 3 | +# Builds o-rly on each target platform and publishes per-architecture |
| 4 | +# artifact tarballs as a GitHub Release keyed by commit SHA. |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: [main] |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + packages: write # reserved for future Docker image publishing |
| 14 | + |
| 15 | +jobs: |
| 16 | + build: |
| 17 | + strategy: |
| 18 | + fail-fast: false |
| 19 | + matrix: |
| 20 | + include: |
| 21 | + - name: ubuntu-22.04-amd64 |
| 22 | + runner: ubuntu-22.04 |
| 23 | + |
| 24 | + name: ${{ matrix.name }} |
| 25 | + runs-on: ${{ matrix.runner }} |
| 26 | + |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@v4 |
| 29 | + with: |
| 30 | + submodules: true |
| 31 | + |
| 32 | + - name: Install system dependencies |
| 33 | + run: bash deps/moxygen/standalone/install-system-deps.sh |
| 34 | + |
| 35 | + - name: Download moxygen release tarball |
| 36 | + env: |
| 37 | + GH_TOKEN: ${{ github.token }} |
| 38 | + run: bash scripts/setup-deps-tarball.sh |
| 39 | + |
| 40 | + - name: Set up ccache |
| 41 | + uses: hendrikmuhs/ccache-action@v1 |
| 42 | + with: |
| 43 | + key: publish-${{ matrix.name }} |
| 44 | + max-size: 500M |
| 45 | + |
| 46 | + - name: Configure |
| 47 | + run: | |
| 48 | + cmake -S . -B _build --preset default \ |
| 49 | + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ |
| 50 | + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ |
| 51 | + -DCMAKE_PREFIX_PATH="$(cat .scratch/cmake_prefix_path.txt)" \ |
| 52 | + -DBUILD_TESTING=OFF |
| 53 | +
|
| 54 | + - name: Build |
| 55 | + run: cmake --build _build -j$(nproc) |
| 56 | + |
| 57 | + - name: Install |
| 58 | + run: cmake --install _build --prefix "$GITHUB_WORKSPACE/install" |
| 59 | + |
| 60 | + - name: Package |
| 61 | + id: package |
| 62 | + run: | |
| 63 | + ARTIFACT="${{ github.event.repository.name }}-${{ matrix.name }}.tar.gz" |
| 64 | + tar czf "$ARTIFACT" -C "$GITHUB_WORKSPACE/install" . |
| 65 | + echo "artifact=$ARTIFACT" >> "$GITHUB_OUTPUT" |
| 66 | +
|
| 67 | + - name: Upload artifact |
| 68 | + uses: actions/upload-artifact@v4 |
| 69 | + with: |
| 70 | + name: ${{ steps.package.outputs.artifact }} |
| 71 | + path: ${{ steps.package.outputs.artifact }} |
| 72 | + retention-days: 90 |
| 73 | + |
| 74 | + release: |
| 75 | + runs-on: ubuntu-22.04 |
| 76 | + needs: [build] |
| 77 | + if: always() |
| 78 | + steps: |
| 79 | + - uses: actions/checkout@v4 |
| 80 | + if: needs.build.result == 'success' |
| 81 | + |
| 82 | + - name: Download all artifacts |
| 83 | + if: needs.build.result == 'success' |
| 84 | + uses: actions/download-artifact@v4 |
| 85 | + with: |
| 86 | + path: artifacts/ |
| 87 | + |
| 88 | + - name: Create release |
| 89 | + if: needs.build.result == 'success' |
| 90 | + env: |
| 91 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 92 | + run: | |
| 93 | + SHORT="${GITHUB_SHA:0:12}" |
| 94 | + TAG="build-${SHORT}" |
| 95 | + gh release create "$TAG" artifacts/**/* \ |
| 96 | + --repo "${{ github.repository }}" \ |
| 97 | + --title "build ${SHORT}" \ |
| 98 | + --notes "Automated release from \`${{ github.ref_name }}\` at \`${SHORT}\`." |
| 99 | +
|
| 100 | + # Prune old releases, keep 20 |
| 101 | + gh api "repos/${{ github.repository }}/releases" \ |
| 102 | + --jq 'sort_by(.created_at) | reverse | .[20:] | .[].tag_name' \ |
| 103 | + | while read -r tag; do |
| 104 | + gh release delete "$tag" --repo "${{ github.repository }}" --yes --cleanup-tag 2>/dev/null || true |
| 105 | + done |
| 106 | +
|
| 107 | + - name: Notify Slack |
| 108 | + if: always() |
| 109 | + continue-on-error: true |
| 110 | + env: |
| 111 | + SLACK_WEBHOOK_URL: ${{ secrets.OMOQ_SLACK_WEBHOOK_URL }} |
| 112 | + run: | |
| 113 | + SHORT="${GITHUB_SHA:0:12}" |
| 114 | + RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
| 115 | + if [ "${{ needs.build.result }}" = "success" ]; then |
| 116 | + REL_URL="${{ github.server_url }}/${{ github.repository }}/releases/tag/build-${SHORT}" |
| 117 | + TEXT=":white_check_mark: *${{ github.repository }}* \`${{ github.ref_name }}\` \`${SHORT}\` — <${REL_URL}|release> · <${RUN_URL}|run>" |
| 118 | + else |
| 119 | + TEXT=":x: *${{ github.repository }}* \`${{ github.ref_name }}\` \`${SHORT}\` — build failed · <${RUN_URL}|run>" |
| 120 | + fi |
| 121 | + curl -s -X POST "$SLACK_WEBHOOK_URL" \ |
| 122 | + -H "Content-Type: application/json" \ |
| 123 | + --data "{\"text\": \"${TEXT}\"}" |
| 124 | +
|
| 125 | + - name: Notify email |
| 126 | + if: always() |
| 127 | + continue-on-error: true |
| 128 | + env: |
| 129 | + AWS_ACCESS_KEY_ID: ${{ secrets.OMOQ_AWS_ACCESS_KEY_ID }} |
| 130 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.OMOQ_AWS_SECRET_ACCESS_KEY }} |
| 131 | + AWS_DEFAULT_REGION: us-east-1 |
| 132 | + run: | |
| 133 | + SHORT="${GITHUB_SHA:0:12}" |
| 134 | + RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}" |
| 135 | + REPO_NAME="${{ github.event.repository.name }}" |
| 136 | + RESULT="${{ needs.build.result }}" |
| 137 | + JOB_STATUS="${{ job.status }}" |
| 138 | + if [ "$RESULT" = "success" ] && [ "$JOB_STATUS" = "success" ]; then |
| 139 | + SUBJECT="[${REPO_NAME}] published ${{ github.ref_name }} ${SHORT}" |
| 140 | + else |
| 141 | + SUBJECT="[${REPO_NAME}] build FAILED ${{ github.ref_name }} ${SHORT}" |
| 142 | + fi |
| 143 | + BODY="${{ github.repository }} · ${{ github.ref_name }} · ${SHORT}\n${RUN_URL}" |
| 144 | + aws ses send-email \ |
| 145 | + --from "noreply@ci.openmoq.org" \ |
| 146 | + --destination '{"ToAddresses":["github-notifications@openmoq.org"]}' \ |
| 147 | + --message "{ |
| 148 | + \"Subject\": {\"Data\": \"$SUBJECT\"}, |
| 149 | + \"Body\": {\"Text\": {\"Data\": \"$BODY\"}} |
| 150 | + }" |
0 commit comments