|
| 1 | +name: Release On Tag |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + # Only match tags that look like go module tags. |
| 7 | + # This way we explicitly ignore our legacy tagging of the operator. |
| 8 | + - '*/v*' |
| 9 | + workflow_dispatch: |
| 10 | + inputs: |
| 11 | + ref_name: |
| 12 | + description: "The ref name to process (e.g., 'operator/v1.2.3')" |
| 13 | + required: false |
| 14 | + default: "" |
| 15 | + |
| 16 | +jobs: |
| 17 | + release: |
| 18 | + name: Create Release on GitHub |
| 19 | + runs-on: ubuntu-latest |
| 20 | + |
| 21 | + steps: |
| 22 | + # for testing purposes and to allow updating of pre-existing releases, |
| 23 | + # this workflow can be triggered by a tag being pushed or directly. This |
| 24 | + # step normalized the possible inputs into a single variable. |
| 25 | + - name: get ref |
| 26 | + id: get_ref |
| 27 | + run: | |
| 28 | + if [[ -n "${{ inputs.ref_name }}" ]]; then |
| 29 | + tag="${{ inputs.ref_name }}" |
| 30 | + else |
| 31 | + tag="${{ github.ref_name }}" |
| 32 | + fi |
| 33 | + echo "using ref name: $tag" |
| 34 | + echo "ref_name=$tag" >> "$github_output" |
| 35 | +
|
| 36 | + - name: checkout code |
| 37 | + uses: actions/checkout@v4 |
| 38 | + with: |
| 39 | + ref: ${{ steps.get_ref.outputs.ref_name }} |
| 40 | + |
| 41 | + - uses: nixbuild/nix-quick-install-action@v30 |
| 42 | + with: |
| 43 | + github_access_token: ${{ secrets.github_token }} |
| 44 | + |
| 45 | + # cache the nix store. |
| 46 | + - uses: nix-community/cache-nix-action@v6 |
| 47 | + with: |
| 48 | + primary-key: nix-${{ runner.os }}-${{ runner.arch }}-${{ hashfiles('**/*.nix', '**/flake.lock') }} |
| 49 | + restore-prefixes-first-match: nix-${{ runner.os }}-${{ runner.arch }} |
| 50 | + |
| 51 | + - name: build release name |
| 52 | + id: release_name |
| 53 | + run: | |
| 54 | + # turn refs into slightly friendlier names. e.g. operator/v1.2.3 -> operator: v1.2.3 |
| 55 | + release_name="$(echo "${{ steps.get_ref.outputs.ref_name }}" | sed 's|/v|: v|')" |
| 56 | + echo "release_name=$release_name" >> "$github_output" |
| 57 | +
|
| 58 | + - name: package helm chart |
| 59 | + run: | |
| 60 | + tag="${{ steps.get_ref.outputs.ref_name }}" |
| 61 | + # extract the directory from the tag (e.g., "operator" from "operator/v1.2.3") |
| 62 | + dir="$(dirname "$tag")" |
| 63 | + # search for chart.yaml in $dir or one directory deep (e.g., operator/chart) |
| 64 | + chart_path=$(find "$dir" -maxdepth 2 -type f -name "chart.yaml" | head -n 1) |
| 65 | + # exit early if no chart.yaml file is found |
| 66 | + if [[ -z "$chart_path" ]]; then |
| 67 | + echo "no chart.yaml found for $tag. skipping step." |
| 68 | + exit 0 |
| 69 | + fi |
| 70 | +
|
| 71 | + echo "packaging chart at $chart_path" |
| 72 | + helm package -u "$(dirname "$chart_path")" |
| 73 | +
|
| 74 | + # create github release and upload file |
| 75 | + - name: create github release |
| 76 | + if: github.ref_type == 'tag' |
| 77 | + uses: softprops/action-gh-release@v2 |
| 78 | + with: |
| 79 | + name: steps.release_name.outputs.release_name |
| 80 | + tag_name: steps.get_ref.outputs.ref_name |
| 81 | + draft: false |
| 82 | + make_latest: false |
| 83 | + prerelease: ${{ contains(steps.get_ref.outputs.ref_name, '-alpha') || contains(steps.get_ref.outputs.ref_name, '-beta') }} |
| 84 | + body_path: ".changes/${{ steps.get_ref.outputs.ref_name }}.md" # pull the release body from changie. |
| 85 | + # if a chart was packaged, we'll upload it to this release preserving helm's naming convention. |
| 86 | + files: | |
| 87 | + ./*.tgz |
| 88 | +
|
| 89 | + # todo(chrisseto) trigger an action in the charts repo that updates index.yaml |
0 commit comments