build-and-publish-release.yml 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. name: Build and Publish Release
  2. on:
  3. push:
  4. tags:
  5. - 'v[0-9]+.[0-9]+.[0-9]+'
  6. workflow_dispatch:
  7. inputs:
  8. release_version:
  9. description: "Version of the release"
  10. required: true
  11. concurrency:
  12. group: build-opencost
  13. cancel-in-progress: true
  14. env:
  15. # Use docker.io for Docker Hub if empty
  16. REGISTRY: ghcr.io
  17. jobs:
  18. build-and-publish-opencost:
  19. runs-on: ubuntu-latest
  20. permissions:
  21. contents: read
  22. packages: write
  23. steps:
  24. - name: Get Version From Tag
  25. id: tag
  26. if: ${{ github.event_name }} == 'push'
  27. run: |
  28. echo "TRIGGERED_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
  29. - name: Determine Version Number
  30. id: version_number
  31. run: |
  32. if [ -z "${TRIGGERED_TAG}" ];
  33. then
  34. version=${{ inputs.release_version }}
  35. else
  36. version=$TRIGGERED_TAG
  37. fi
  38. if [[ ${version:0:1} == "v" ]];
  39. then
  40. echo "RELEASE_VERSION=${version:1}" >> $GITHUB_OUTPUT
  41. else
  42. echo "RELEASE_VERSION=$version" >> $GITHUB_OUTPUT
  43. fi
  44. - name: Show Input Values
  45. run: |
  46. echo "release version: ${{ inputs.release_version }}"
  47. - name: Make Branch Name
  48. id: branch
  49. run: |
  50. VERSION_NUMBER=${{ steps.version_number.outputs.RELEASE_VERSION }}
  51. echo "BRANCH_NAME=v${VERSION_NUMBER%.*}" >> $GITHUB_OUTPUT
  52. - name: Checkout Repo
  53. uses: actions/checkout@v4
  54. with:
  55. ref: '${{ steps.branch.outputs.BRANCH_NAME }}'
  56. - name: Set SHA
  57. id: sha
  58. run: |
  59. echo "OC_SHORTHASH=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
  60. - name: Set OpenCost Image Tags
  61. id: tags
  62. run: |
  63. echo "IMAGE_TAG=ghcr.io/${{ github.repository_owner }}/opencost:${{ steps.sha.outputs.OC_SHORTHASH }}" >> $GITHUB_OUTPUT
  64. echo "IMAGE_TAG_LATEST=ghcr.io/${{ github.repository_owner }}/opencost:latest" >> $GITHUB_OUTPUT
  65. echo "IMAGE_TAG_VERSION=ghcr.io/${{ github.repository_owner }}/opencost:${{ steps.version_number.outputs.RELEASE_VERSION }}" >> $GITHUB_OUTPUT
  66. - name: Build and publish container
  67. uses: ./.github/actions/build-container
  68. with:
  69. actor: ${{ github.actor }}
  70. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  71. image_tag: ${{ steps.tags.outputs.IMAGE_TAG }}
  72. release_version: ${{ steps.version_number.outputs.RELEASE_VERSION }}
  73. - name: Log into registry ${{ env.REGISTRY }}
  74. uses: docker/login-action@v3
  75. with:
  76. registry: ${{ env.REGISTRY }}
  77. username: ${{ github.actor }}
  78. password: ${{ secrets.GITHUB_TOKEN }}
  79. - name: Install crane
  80. uses: imjasonh/setup-crane@v0.4
  81. - name: Copy tags
  82. run: |
  83. crane copy '${{ steps.tags.outputs.IMAGE_TAG }}' '${{ steps.tags.outputs.IMAGE_TAG_LATEST }}'
  84. crane copy '${{ steps.tags.outputs.IMAGE_TAG }}' '${{ steps.tags.outputs.IMAGE_TAG_VERSION }}'