diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6c16733..a39ff03 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,11 +20,18 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 + - uses: octokit/request-action@v2.x + id: get_latest_release + with: + route: GET /repos/{repo}/releases/latest + repo: ${{ github.repository }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Generate trunkver id: trunkver uses: crftd-tech/trunkver@main with: - baseVersion: "1.0.0" + baseVersion: ${{ fromJson(steps.get_latest_release.outputs.data).tag_name }} prerelease: "true" build-release: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..8c35134 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,80 @@ +name: Release + +on: + workflow_dispatch: + inputs: + version: + required: true + description: The version to release + +permissions: + packages: write + contents: write + +jobs: + build-docker: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Generate metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ghcr.io/crftd-tech/trunkver + tags: | + type=raw,value=${{ github.event.inputs.version }} + type=raw,value=latest + + - name: Log in to the Container registry + uses: docker/login-action@327cd5a69de6c009b9ce71bce8395f28e651bf99 + with: + registry: "ghcr.io" + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@31ca4e5d51253d7e4a2317bfe74699cbe3a398a9 + with: + context: . + build-args: | + VERSION=${{ github.event.inputs.version }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + - name: Update the action.yml with the new image tag + run: | + yq eval --inplace '.runs.image = "docker://ghcr.io/crftd-tech/trunkver:${{ github.event.inputs.version }}"' action.yml + git config --global user.email "bot@crftd.tech" + git config --global user.name "crftd-bot" + git add action.yml + git commit -m "chore: Bump image tag in action.yml" + git pull origin --rebase + git push origin + + build-release: + runs-on: ubuntu-latest + needs: [build-docker] + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: 1.22 + - name: Build trunkver + env: + VERSION: ${{ github.event.inputs.version }} + run: | + ( + unset GITHUB_SHA + unset GITHUB_RUN_ID + make test all spec "VERSION=${VERSION}" + ) + - name: Create release + id: release + uses: softprops/action-gh-release@v2 + with: + name: ${{ github.event.inputs.version }} + tag_name: ${{ github.event.inputs.version }} + files: | + out/trunkver* \ No newline at end of file