|
| 1 | +name: Docker Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + tag: |
| 10 | + description: Git tag to release, for example v0.2.0 |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: write |
| 16 | + |
| 17 | +jobs: |
| 18 | + release: |
| 19 | + name: Build, Publish, and Release |
| 20 | + runs-on: ubuntu-latest |
| 21 | + environment: dockerhub |
| 22 | + |
| 23 | + steps: |
| 24 | + - name: Determine release tag |
| 25 | + id: version |
| 26 | + run: | |
| 27 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 28 | + TAG="${{ inputs.tag }}" |
| 29 | + else |
| 30 | + TAG="${{ github.ref_name }}" |
| 31 | + fi |
| 32 | +
|
| 33 | + case "$TAG" in |
| 34 | + v*) |
| 35 | + VERSION="${TAG#v}" |
| 36 | + ;; |
| 37 | + *) |
| 38 | + echo "Tag must start with v, got: $TAG" >&2 |
| 39 | + exit 1 |
| 40 | + ;; |
| 41 | + esac |
| 42 | +
|
| 43 | + echo "tag=$TAG" >> "$GITHUB_OUTPUT" |
| 44 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 45 | +
|
| 46 | + - name: Check out repository |
| 47 | + uses: actions/checkout@v4 |
| 48 | + with: |
| 49 | + ref: ${{ steps.version.outputs.tag }} |
| 50 | + |
| 51 | + - name: Set up Docker Buildx |
| 52 | + uses: docker/setup-buildx-action@v3 |
| 53 | + |
| 54 | + - name: Log in to Docker Hub |
| 55 | + uses: docker/login-action@v3 |
| 56 | + with: |
| 57 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 58 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 59 | + |
| 60 | + - name: Build and push Docker image |
| 61 | + uses: docker/build-push-action@v6 |
| 62 | + with: |
| 63 | + context: . |
| 64 | + push: true |
| 65 | + build-args: | |
| 66 | + APP_VERSION=${{ steps.version.outputs.version }} |
| 67 | + tags: | |
| 68 | + worryboy/internetx-dyndns:${{ steps.version.outputs.version }} |
| 69 | + worryboy/internetx-dyndns:latest |
| 70 | +
|
| 71 | + - name: Create GitHub Release |
| 72 | + uses: softprops/action-gh-release@v2 |
| 73 | + with: |
| 74 | + tag_name: ${{ steps.version.outputs.tag }} |
| 75 | + generate_release_notes: true |
0 commit comments