|
| 1 | +--- |
| 2 | +name: 'Release' |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - 'main' |
| 7 | +jobs: |
| 8 | + |
| 9 | + draft-release: |
| 10 | + name: 'Draft Release' |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - name: 'Check out code' |
| 14 | + uses: actions/checkout@v4 |
| 15 | + - name: 'Make release' |
| 16 | + id: 'make-release' |
| 17 | + env: |
| 18 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 19 | + run: | |
| 20 | + set -x |
| 21 | + VERSION=v$(cat package/version) |
| 22 | + gh release create "${VERSION}" \ |
| 23 | + --repo "${GITHUB_REPOSITORY}" \ |
| 24 | + --draft \ |
| 25 | + --title "${VERSION}" \ |
| 26 | + --target ${{ github.sha }} |
| 27 | + echo "version=${VERSION}" >> "$GITHUB_OUTPUT" |
| 28 | +
|
| 29 | + nix-cache: |
| 30 | + name: 'Populate Nix Caches' |
| 31 | + strategy: |
| 32 | + matrix: |
| 33 | + runner: [normal, ARM64] |
| 34 | + runs-on: ${{ matrix.runner }} |
| 35 | + needs: draft-release |
| 36 | + steps: |
| 37 | + - name: 'Check out code' |
| 38 | + uses: actions/checkout@v4 |
| 39 | + with: |
| 40 | + ref: ${{ github.sha }} |
| 41 | + fetch-depth: 0 |
| 42 | + |
| 43 | + # Build the komet-node derivation once, then push it to both the public |
| 44 | + # k-framework cache (full build closure, via `cachix push`) and the |
| 45 | + # private k-framework-binary cache (the kup-installable binary, via |
| 46 | + # `kup publish`). Both pushes reuse the build output already present in |
| 47 | + # this runner's Nix store, so the derivation is never built twice. |
| 48 | + - name: 'Build and publish komet-node to both Nix caches' |
| 49 | + uses: workflow/nix-shell-action@v3 |
| 50 | + env: |
| 51 | + GC_DONT_GC: '1' |
| 52 | + # Enable flakes for every nix invocation in this step (the initial |
| 53 | + # build, the kup build, and the builds kup runs internally) so the |
| 54 | + # job does not depend on flakes being globally enabled on the runner. |
| 55 | + NIX_CONFIG: 'extra-experimental-features = nix-command flakes' |
| 56 | + CACHIX_PUBLIC_TOKEN: '${{ secrets.CACHIX_PUBLIC_TOKEN }}' |
| 57 | + CACHIX_PRIVATE_KFB_TOKEN: '${{ secrets.CACHIX_PRIVATE_KFB_TOKEN }}' |
| 58 | + OWNER_REPO: '${{ github.repository }}' |
| 59 | + REV: '${{ github.sha }}' |
| 60 | + with: |
| 61 | + packages: jq |
| 62 | + script: | |
| 63 | + KOMET_NODE=$(nix build .#komet-node --json | jq -r '.[].outputs | to_entries[].value') |
| 64 | + DRV=$(nix-store --query --deriver ${KOMET_NODE}) |
| 65 | +
|
| 66 | + # Push the full build closure to the public k-framework cache. |
| 67 | + export CACHIX_AUTH_TOKEN="${CACHIX_PUBLIC_TOKEN}" |
| 68 | + nix-store --query --requisites --include-outputs ${DRV} | cachix push k-framework |
| 69 | +
|
| 70 | + # Publish the binary to the private k-framework-binary cache. kup |
| 71 | + # reuses the store paths built above. |
| 72 | + export CACHIX_AUTH_TOKEN="${CACHIX_PRIVATE_KFB_TOKEN}" |
| 73 | + export PATH="$(nix build github:runtimeverification/kup --no-link --json | jq -r '.[].outputs | to_entries[].value')/bin:$PATH" |
| 74 | + kup publish k-framework-binary .#komet-node --keep-days 180 |
| 75 | + # Cachix has not been responding to 'cachix pin' requests made under the hood by kup. Verify the push and pin manually. |
| 76 | + .github/scripts/check-cachix-pin.sh |
| 77 | +
|
| 78 | + - name: 'On failure, delete drafted release' |
| 79 | + if: failure() |
| 80 | + env: |
| 81 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 82 | + run: | |
| 83 | + set -x |
| 84 | + VERSION=v$(cat package/version) |
| 85 | + gh release delete "${VERSION}" \ |
| 86 | + --repo "${GITHUB_REPOSITORY}" \ |
| 87 | + --yes \ |
| 88 | + --cleanup-tag |
| 89 | +
|
| 90 | + dockerhub: |
| 91 | + name: 'Build and Publish Docker Image' |
| 92 | + runs-on: [self-hosted, linux, normal] |
| 93 | + needs: draft-release |
| 94 | + steps: |
| 95 | + - name: 'Check out code' |
| 96 | + uses: actions/checkout@v4 |
| 97 | + with: |
| 98 | + ref: ${{ github.sha }} |
| 99 | + fetch-depth: 0 |
| 100 | + |
| 101 | + - name: 'Set environment' |
| 102 | + run: | |
| 103 | + KOMET_NODE_VERSION=$(cat package/version) |
| 104 | + TAG=runtimeverificationinc/komet-node:ubuntu-jammy-${KOMET_NODE_VERSION} |
| 105 | + echo "TAG=${TAG}" >> ${GITHUB_ENV} |
| 106 | +
|
| 107 | + - name: 'Build Docker image' |
| 108 | + run: | |
| 109 | + K_VERSION=$(cat deps/k_release) |
| 110 | + docker build . --no-cache --tag ${TAG} --build-arg K_VERSION=${K_VERSION} |
| 111 | +
|
| 112 | + - name: 'Run Docker image' |
| 113 | + run: docker run --rm ${TAG} komet-node --help |
| 114 | + |
| 115 | + - name: 'Push Docker image to Docker Hub' |
| 116 | + run: | |
| 117 | + echo "${{ secrets.DOCKERHUB_PASSWORD }}" | docker login --username rvdockerhub --password-stdin |
| 118 | + docker image push ${TAG} |
| 119 | +
|
| 120 | + - name: 'On failure, delete drafted release' |
| 121 | + if: failure() |
| 122 | + env: |
| 123 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 124 | + run: | |
| 125 | + set -x |
| 126 | + VERSION=v$(cat package/version) |
| 127 | + gh release delete "${VERSION}" \ |
| 128 | + --repo "${GITHUB_REPOSITORY}" \ |
| 129 | + --yes \ |
| 130 | + --cleanup-tag |
| 131 | +
|
| 132 | + cut-release: |
| 133 | + name: 'Cut Release' |
| 134 | + runs-on: ubuntu-latest |
| 135 | + needs: [dockerhub, nix-cache] |
| 136 | + steps: |
| 137 | + - name: 'Check out code' |
| 138 | + uses: actions/checkout@v4 |
| 139 | + with: |
| 140 | + ref: ${{ github.sha }} |
| 141 | + fetch-depth: 0 |
| 142 | + |
| 143 | + - name: 'Finalize Release' |
| 144 | + env: |
| 145 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 146 | + run: | |
| 147 | + set -x |
| 148 | + VERSION=v$(cat package/version) |
| 149 | + gh release edit "${VERSION}" \ |
| 150 | + --repo "${GITHUB_REPOSITORY}" \ |
| 151 | + --draft=false |
0 commit comments