-
Notifications
You must be signed in to change notification settings - Fork 16
170 lines (167 loc) · 6.5 KB
/
release-upload.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
name: Release Upload
# This makes it easy to get download release binaries built using
# a github action for any tagged commit.
#
# This workflow builds and uploads the macOS, win64 and linux
# binary packages as github assets.
#
# It uses `--builders "" --max-jobs 0` to ensure the assets are
# from the IOG cache.
on:
workflow_dispatch:
inputs:
target_tag:
description: 'The tag of the release to attach binaries to'
default: ''
required: false
type: string
release:
types:
- published
push:
tags:
- '**'
env:
GH_TOKEN: ${{ github.token }}
jobs:
wait_for_hydra:
name: "Wait for hydra check-runs"
runs-on: ubuntu-latest
outputs:
TARGET_TAG: ${{ steps.check_target_tag.outputs.TARGET_TAG }}
FLAKE_REF: ${{ steps.define_flake_ref.outputs.FLAKE_REF }}
steps:
- name: Define target tag (1/2)
if: ${{ inputs.target_tag != '' }} # If a tag was specified manually as input, use it
run: |
echo "TARGET_TAG=${{ inputs.target_tag }}" >> "$GITHUB_ENV"
- name: Define target tag (2/2)
if: ${{ inputs.target_tag == '' }} # If no tag was specified manually as input, take the tag from the current commit
run: |
current_tag=$(git tag --points-to HEAD | head -n 1)
if [[ "$current_tag" != "" ]]
then
# The workflow runs on a commit that has a tag, use this tag
echo "TARGET_TAG=$current_tag" >> "$GITHUB_ENV"
fi
- name: Check tag is defined
id: check_target_tag
run: |
if [[ "${{ env.TARGET_TAG }}" == "" ]]
then
echo "The tag to build binaries for is undefined! Either:"
echo "- This pipeline should run on a commit that has a tag"
echo "- This pipeline should be executed manually and the tag to target should be specified with the 'target_tag' input"
exit 1
fi
echo "TARGET_TAG=${{ env.TARGET_TAG }}" >> "$GITHUB_OUTPUT"
- name: Define FLAKE_REF
id: define_flake_ref
run: |
flake_ref="github:${{ github.repository }}/${{ env.TARGET_TAG }}"
echo "FLAKE_REF=$flake_ref" >> "$GITHUB_ENV"
echo "FLAKE_REF=$flake_ref" >> "$GITHUB_OUTPUT"
- name: Get specific check run status
timeout-minutes: 120
run: |
while true; do
# When supporting other architectures than Linux, this query should be adapted:
conclusion=$(gh api "repos/$GITHUB_REPOSITORY/commits/${{ env.TARGET_TAG }}/check-runs" --jq '.check_runs[] | select(.name | test("ci/hydra-build:.*-linux.required")) | .conclusion')
case "$conclusion" in
success)
echo "ci/hydra-build:required succeeded"
exit 0;;
failure)
echo "ci/hydra-build:required failed"
exit 1;;
*)
echo "ci/hydra-build:required pending. Waiting 30s..."
sleep 30;;
esac
done
pull:
needs: [wait_for_hydra]
strategy:
matrix:
arch: [linux]
# TODO generalize
# arch: [linux, macos, win64]
name: "Download Asset from the Cache"
runs-on: ubuntu-latest
steps:
- name: Install Nix with good defaults
uses: input-output-hk/install-nix-action@v20
with:
extra_nix_config: |
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=
substituters = https://cache.iog.io/ https://cache.nixos.org/
nix_path: nixpkgs=channel:nixos-unstable
- name: Display flake metadata
id: flake-metadata
run: |
nix flake metadata "${{ needs.wait_for_hydra.outputs.FLAKE_REF }}"
nix flake metadata "${{ needs.wait_for_hydra.outputs.FLAKE_REF }}" --json | jq -r '"LOCKED_URL=\(.url)"' >> "$GITHUB_ENV"
- name: Build
run: |
case ${{ matrix.arch }} in
linux)
nix build --builders "" --max-jobs 0 ${{ env.LOCKED_URL }}#cardano-cli:exe:cardano-cli
tree result
cp result/bin/cardano-cli cardano-cli-${{ matrix.arch }} # (1)
;;
# TODO generalize
# Those need fixing, they have not been tested. But so far they are disabled,
# because the only platform tested on hydra is Linux (see flake.nix)
# macos)
# nix build --builders "" --max-jobs 0 ${{ steps.flake-metadata.outputs.LOCKED_URL }}#cardano-cli:exe:cardano-cli
# tree result
# ;;
# win64)
# nix build --builders "" --max-jobs 0 ${{ steps.flake-metadata.outputs.LOCKED_URL }}#x86_64-w64-mingw32:cardano-cli:exe:cardano-cli
# tree result
# ;;
esac
- uses: actions/upload-artifact@v4
with:
name: cardano-cli-${{ matrix.arch }} # (2)
path: cardano-cli-* # Should match (1)
retention-days: 1
upload-assets:
needs: [wait_for_hydra, pull]
name: "Upload Assets"
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v4
with:
name: cardano-cli-linux # Should match (2)
# TODO generalize
# - uses: actions/download-artifact@v3
# with:
# name: cardano-cli-macos # Should match (2)
# - uses: actions/download-artifact@v3
# with:
# name: cardano-cli-win64 # Should match (2)
- name: Tree
run: tree
- name: Compress
run: |
# (3)
# TARGET_TAG is of the form cardano-cli-8.22.0, so we don't need to prefix the tar.gz's name
# with cardano-cli
tar -czf ${{ needs.wait_for_hydra.outputs.TARGET_TAG }}-linux.tar.gz cardano-cli-linux
# TODO generalize
# tar -czf ${{ needs.wait_for_hydra.outputs.TARGET_TAG }}-macos.tar.gz cardano-cli-macos
# zip ${{ needs.wait_for_hydra.outputs.TARGET_TAG }}-win64.zip cardano-cli-win64
- name: Tree
run: tree
- name: Release
uses: input-output-hk/action-gh-release@v1
with:
draft: true
tag_name: ${{ needs.wait_for_hydra.outputs.TARGET_TAG }}
# TODO generalize
# cardano-cli-${{ needs.wait_for_hydra.outputs.TARGET_TAG }}-macos.tar.gz
# cardano-cli-${{ needs.wait_for_hydra.outputs.TARGET_TAG }}-win64.zip
# All entries in 'files' below should match (3)
files: |
${{ needs.wait_for_hydra.outputs.TARGET_TAG }}-linux.tar.gz