From 19e70ffc6927ad217709c28ef01cc35d685efdf0 Mon Sep 17 00:00:00 2001 From: Adel Salakh Date: Wed, 14 May 2025 22:28:25 +0200 Subject: [PATCH] Update publish-release.yml --- .github/workflows/publish-release.yml | 191 ++++++++++++-------------- 1 file changed, 87 insertions(+), 104 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 35f38b40..a52a24e0 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -1,135 +1,118 @@ name: Publish Release -run-name: ${{ github.event.pull_request.head.ref }} +run-name: Release ${{ github.event.inputs.version }} on: - pull_request_target: - branches: - - master - types: - - closed + workflow_dispatch: + inputs: + version: + description: 'Release version (e.g. v1.2.3)' + required: true + type: string permissions: contents: write - pull-requests: write jobs: publish: - if: github.event.pull_request.merged && startsWith(github.event.pull_request.head.ref, 'release/') runs-on: ubuntu-latest outputs: tag: ${{ steps.tag.outputs.version }} steps: - - name: Check out code - uses: actions/checkout@v4 - with: - ref: ${{ github.event.pull_request.merge_commit_sha }} - fetch-depth: 0 - fetch-tags: true + - name: Check out code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true - - name: Tag release - run: | - # Set up github-actions[bot] user - git config --local user.name "github-actions[bot]" - git config --local user.email "github-actions[bot]@users.noreply.github.com" + - name: Tag release + id: tag + run: | + # Set up github-actions[bot] user + git config --local user.name "github-actions[bot]" + git config --local user.email "github-actions[bot]@users.noreply.github.com" - # Get the version from the branch name - branch="${{ github.event.pull_request.head.ref }}" - version="${branch#release/}" - echo ${version} + # Use version from input + version="${{ github.event.inputs.version }}" + echo "Tagging release $version" - # Tag and create release - git tag -a "${version}" -m "Release ${version}" - echo "version=${version}" >> $GITHUB_OUTPUT - id: tag - - - name: Set up go - uses: actions/setup-go@v5 - with: - go-version-file: go.mod + # Create annotated tag + git tag -a "$version" -m "Release $version" + echo "version=$version" >> $GITHUB_OUTPUT - - name: Get dependencies - env: - # renovate: datasource=github-tags depName=golangci/golangci-lint - GOLANGCI_LINT_VERSION: v1.64.8 - run: | - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION} - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter - chmod +x ./cc-test-reporter + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod - # Install go dependencies - go mod download + - name: Get dependencies + env: + GOLANGCI_LINT_VERSION: v1.64.8 + run: | + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin ${GOLANGCI_LINT_VERSION} + curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter + chmod +x ./cc-test-reporter + go mod download - - name: Build Artifacts - run: make release - - # Upload artifacts in case of workflow failure - - name: Upload Artifacts - uses: actions/upload-artifact@v4 - with: - name: oauth2-proxy-artifacts - path: | - release/*.tar.gz - release/*.txt + - name: Build Artifacts + run: make release - - name: Create release - env: - GH_TOKEN: ${{ github.token }} - run: | - # Get version from tag - version=$(git describe --tags --abbrev=0) + - name: Upload Artifacts + if: failure() + uses: actions/upload-artifact@v4 + with: + name: oauth2-proxy-artifacts + path: | + release/*.tar.gz + release/*.txt - # Extract CHANGELOG - numericVersion="${version#v}" - notes=$(sed -E "/^# (v|V)$numericVersion$/,/^# (v|V)/!d;//d" CHANGELOG.md) + - name: Push tag + run: git push origin "${{ steps.tag.outputs.version }}" - # Publish release tag - git push origin "${version}" + - name: Create GitHub release + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + version=${{ steps.tag.outputs.version }} + numericVersion="${version#v}" + notes=$(sed -n "/^# ${numericVersion}$/,/^# /{ /# ${numericVersion}$/d; /# /!p }" CHANGELOG.md) + gh release create "$version" \ + --title "$version" \ + --notes "$notes" \ + --prerelease \ + && gh release upload "$version" release/*.tar.gz release/*.txt - # Create github release - gh release create "${version}" \ - --title "${version}" \ - --notes "${notes}" \ - --prerelease - - # Upload artifacts - gh release upload "${version}" release/*.tar.gz - gh release upload "${version}" release/*.txt - docker: needs: publish runs-on: ubuntu-latest steps: + - name: Check out code + uses: actions/checkout@v4 + with: + ref: ${{ needs.publish.outputs.tag }} + fetch-depth: 0 + fetch-tags: true - - name: Check out code - uses: actions/checkout@v4 - with: - ref: ${{ needs.publish.outputs.tag }} - fetch-depth: 0 - fetch-tags: true + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: ${{ vars.AWS_ECR_ROLE }} + aws-region: ${{ vars.AWS_REGION }} - - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v4 - with: - role-to-assume: ${{ vars.AWS_ECR_ROLE }} - aws-region: ${{ vars.AWS_REGION }} + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to ECR - id: ecr_login - uses: aws-actions/amazon-ecr-login@v1 - with: - mask-password: 'true' + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v3 - - name: Build images - run: | - make build-docker-all - - - name: Push images - run: | - make push-docker-all + - name: Login to ECR + id: ecr_login + uses: aws-actions/amazon-ecr-login@v1 + with: + mask-password: 'true' + + - name: Build images + run: make build-docker-all + + - name: Push images + run: make push-docker-all