build-and-publish-release.yml 3.3 KB

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