|
| 1 | +--- |
| 2 | +name: Create new release |
| 3 | +'on': |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + ref: |
| 9 | + description: 'Git tag to push the image' |
| 10 | + required: true |
| 11 | + type: string |
| 12 | +jobs: |
| 13 | + docker: |
| 14 | + name: Build image |
| 15 | + runs-on: ubuntu-latest |
| 16 | + # https://docs.github.com/en/actions/use-cases-and-examples/publishing-packages/publishing-docker-images#publishing-images-to-github-packages |
| 17 | + permissions: |
| 18 | + packages: write |
| 19 | + contents: read |
| 20 | + attestations: write |
| 21 | + id-token: write |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Check out code |
| 25 | + uses: actions/checkout@v4 |
| 26 | + with: |
| 27 | + ref: ${{ inputs.ref }} |
| 28 | + - name: Docker meta |
| 29 | + id: meta |
| 30 | + uses: docker/metadata-action@v5 |
| 31 | + with: |
| 32 | + context: ${{ inputs.ref && 'git' || 'workflow' }} |
| 33 | + images: ghcr.io/${{ github.repository }} |
| 34 | + # create latest tag for branch events |
| 35 | + flavor: | |
| 36 | + latest=${{ inputs.ref && 'false' || 'auto' }} |
| 37 | + tags: | |
| 38 | + type=semver,pattern={{version}},value=${{inputs.ref}} |
| 39 | + type=semver,pattern={{major}}.{{minor}},value=${{inputs.ref}} |
| 40 | + type=semver,pattern={{major}}.{{minor}}.{{patch}},value=${{inputs.ref}} |
| 41 | + - name: Login to ghcr.io |
| 42 | + uses: docker/login-action@v3 |
| 43 | + with: |
| 44 | + registry: ghcr.io |
| 45 | + username: ${{ github.actor }} |
| 46 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 47 | + - name: Build and push |
| 48 | + id: docker_build |
| 49 | + uses: docker/build-push-action@v5 |
| 50 | + with: |
| 51 | + # push for non-pr events |
| 52 | + push: ${{ github.event_name != 'pull_request' }} |
| 53 | + context: . |
| 54 | + tags: ${{ steps.meta.outputs.tags }} |
| 55 | + labels: ${{ steps.meta.outputs.labels }} |
| 56 | + |
| 57 | + build: |
| 58 | + name: Publish assets and packages |
| 59 | + runs-on: ubuntu-latest |
| 60 | + permissions: |
| 61 | + contents: write |
| 62 | + |
| 63 | + steps: |
| 64 | + - uses: actions/checkout@v4 |
| 65 | + name: Checkout |
| 66 | + with: |
| 67 | + # Otherwise there's a risk to not get latest tag |
| 68 | + # We hope, that the current commit at |
| 69 | + # least 100 commits close to the latest release |
| 70 | + fetch-depth: 100 |
| 71 | + fetch-tags: ${{ inputs.ref != '' }} |
| 72 | + ref: ${{ inputs.ref }} |
| 73 | + - name: Set up Go 1 |
| 74 | + uses: actions/setup-go@v5 |
| 75 | + with: |
| 76 | + go-version: ^1 |
| 77 | + - name: Build packages |
| 78 | + id: build |
| 79 | + run: | |
| 80 | + go install github.com/goreleaser/nfpm/v2/cmd/[email protected] |
| 81 | + make -e CGO_ENABLED=0 packages |
| 82 | + - name: Upload release assets |
| 83 | + env: |
| 84 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 85 | + run: | |
| 86 | + TAG="${{ inputs.ref && inputs.ref || github.event.release.tag_name }}" |
| 87 | + gh release upload --clobber --repo ${{ github.repository }} "$TAG" \ |
| 88 | + out/*.deb out/*.rpm out/*sum |
| 89 | + - name: Upload packages to packagecloud.com |
| 90 | + env: |
| 91 | + PACKAGECLOUD_TOKEN: ${{ secrets.PACKAGECLOUD_TOKEN }} |
| 92 | + run: | |
| 93 | + go install github.com/mlafeldt/pkgcloud/cmd/pkgcloud-push@e79e9efc |
| 94 | + make packagecloud-stable |
0 commit comments