Skip to content

Commit

Permalink
feat: more release improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
tagoro9 committed Sep 18, 2024
1 parent f1c5f86 commit 848cd55
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 36 deletions.
2 changes: 2 additions & 0 deletions docs/breaking-changes/v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
The `go-version` input in the `release` and `prerelease` actions no longer exists.

The action will use the installed version in the runner.

The `push-docker-snapshot` input in the `prerelease` action no longer exists. Instead, set the `create-release` input to true.
1 change: 0 additions & 1 deletion prerelease/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ GitHub Action that produces a new pre-release (snapshot) of a golang based repos
| `checkout-fetch-depth` | <p>The number of commits to fetch. 0 indicates all history for all branches and tags</p> | `false` | `0` |
| `create-prerelease` | <p>Whether semantic-release should create a prerelease or do a dry run. This can be useful to set to true when a prerelease requires pushing artifacts semantic-release is in charge of generating</p> | `false` | `false` |
| `github-token` | <p>GitHub token that can checkout the consumer repository as well as create tags/releases against it. e.g. 'secrets.GITHUB_TOKEN'</p> | `true` | `""` |
| `push-docker-snapshot` | <p>If a docker snapshot image is generated, push it to the to the registry</p> | `false` | `false` |
| `docker-username` | <p>Docker username to push the snapshot image to the registry</p> | `false` | `""` |
| `docker-password` | <p>Docker password to push the snapshot image to the registry</p> | `false` | `""` |
| `extra-plugins` | <p>Extra plugins for pre-install. You can also specify specifying version range for the extra plugins if you prefer. Defaults to install @open-turo/semantic-release-config.</p> | `false` | `@open-turo/semantic-release-config ` |
Expand Down
54 changes: 28 additions & 26 deletions prerelease/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ inputs:
github-token:
description: GitHub token that can checkout the consumer repository as well as create tags/releases against it. e.g. 'secrets.GITHUB_TOKEN'
required: true
# TODO Could this be replaced by create-prerelease + the presence of the docker credentials?
push-docker-snapshot:
description: If a docker snapshot image is generated, push it to the to the registry
required: false
default: "false"
docker-username:
description: Docker username to push the snapshot image to the registry
required: false
Expand Down Expand Up @@ -128,45 +123,52 @@ runs:
echo "version=${{ steps.prerelease.outputs.new-release-version }}" >> $GITHUB_OUTPUT
echo "run-url=https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> "$GITHUB_OUTPUT"
- name: Set Go Version
shell: bash
run: |
echo "GOVERSION=$(< .go-version tr -d '\n')" >> $GITHUB_ENV
- name: Docker login
if: inputs.docker-username != '' && inputs.docker-password != '' && steps.prerelease.outputs.new-release-version != ''
uses: docker/login-action@v3
with:
username: ${{ inputs.docker-username }}
password: ${{ inputs.docker-password }}

- name: Goreleaser
uses: goreleaser/goreleaser-action@v6
id: goreleaser
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
with:
args: release

- name: Docker login
if: inputs.push-docker-snapshot == 'true'
uses: docker/login-action@v3
with:
username: ${{ inputs.docker-username }}
password: ${{ inputs.docker-password }}
- name: Push Snapshot Image
if: inputs.push-docker-snapshot == 'true'
# - name: Push Snapshot Image
# if: inputs.push-docker-snapshot == 'true'
# shell: bash
# run: |
# # Selects all the docker images that are not the latest tag.
# # Maybe this doesn't cover all the cases and we could add an input to specify the tag format to push.
# DOCKER_IMAGES=$(jq -r '.[] | select(.type == "Docker Image") | .path' dist/artifacts.json | grep -v ':latest')
# for image in $DOCKER_IMAGES; do
# docker push $image
# done

- name: Get docker artifacts
id: get-docker-artifacts
if: steps.prerelease.outputs.new-release-published == 'true'
shell: bash
env:
GORELEASER_ARTIFACTS: ${{ steps.goreleaser.outputs.artifacts }}
run: |
# Selects all the docker images that are not the latest tag.
# Maybe this doesn't cover all the cases and we could add an input to specify the tag format to push.
DOCKER_IMAGES=$(jq -r '.[] | select(.type == "Docker Image") | .path' dist/artifacts.json | grep -v ':latest')
for image in $DOCKER_IMAGES; do
docker push $image
done
ARTIFACTS=$(echo $GORELEASER_ARTIFACTS | jq -r '.[] | select(.type == "Docker Image"))
echo "artifacts=$ARTIFACTS" >> $GITHUB_OUTPUT
- name: Add new version to summary
shell: bash
if: steps.prerelease.outputs.new-release-published == 'true'
env:
NEW_VERSION: ${{ steps.vars.outputs.version }}
DOCKER_IMAGE: ${{ steps.build-docker.outputs.image-with-tag }}
GORELEASER_ARTIFACTS: ${{ steps.get-docker-artifacts.artifacts }}
run: |
echo "::notice::new version: \`${NEW_VERSION}\`"
echo "#### New version: \`${NEW_VERSION}\`" >> $GITHUB_STEP_SUMMARY
echo "#### Docker image: \`${DOCKER_IMAGE}\`" >> $GITHUB_STEP_SUMMARY
echo "#### Artifacts: \`${GORELEASER_ARTIFACTS}\`" >> $GITHUB_STEP_SUMMARY
- name: Add no new version to summary
shell: bash
Expand Down Expand Up @@ -201,6 +203,6 @@ runs:
## Prerelease build
**Build version:** `${{ steps.vars.outputs.version }}`
**Docker image:** `${{ steps.build-docker.outputs.image-with-tag }}`
**Artifacts:** `${{ steps.get-docker-artifacts.artifacts }}`
[Build output](${{ steps.vars.outputs.run-url }})
14 changes: 14 additions & 0 deletions release/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ GitHub Action that produces a new Release of a golang based repository.
| `github-token` | <p>GitHub token that can checkout the consumer repository as well as create tags/releases against it. e.g. 'secrets.GITHUB_TOKEN'</p> | `true` | `""` |
| `dry-run` | <p>Whether to run semantic release in <code>dry-run</code> mode. It will override the <code>dryRun</code> attribute in your configuration file</p> | `false` | `false` |
| `extra-plugins` | <p>Extra plugins for pre-install. You can also specify specifying version range for the extra plugins if you prefer. Defaults to install @open-turo/semantic-release-config.</p> | `false` | `@open-turo/semantic-release-config ` |
| `docker-username` | <p>Docker username to push the snapshot image to the registry</p> | `false` | `""` |
| `docker-password` | <p>Docker password to push the snapshot image to the registry</p> | `false` | `""` |
<!-- action-docs-inputs source="action.yaml" -->
## Inputs

Expand Down Expand Up @@ -92,6 +94,18 @@ This action is a `composite` action.
#
# Required: false
# Default: @open-turo/semantic-release-config

docker-username:
# Docker username to push the snapshot image to the registry
#
# Required: false
# Default: ""

docker-password:
# Docker password to push the snapshot image to the registry
#
# Required: false
# Default: ""
```
<!-- action-docs-usage source="action.yaml" -->
<!-- action-docs-usage -->
Expand Down
23 changes: 14 additions & 9 deletions release/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ inputs:
description: Extra plugins for pre-install. You can also specify specifying version range for the extra plugins if you prefer. Defaults to install @open-turo/semantic-release-config.
default: |
@open-turo/semantic-release-config
docker-username:
description: Docker username to push the snapshot image to the registry
required: false
docker-password:
description: Docker password to push the snapshot image to the registry
required: false
outputs:
version:
description: Version of the project
Expand Down Expand Up @@ -62,13 +68,14 @@ runs:
github-token: ${{ inputs.github-token }}
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
# Since the release is created with semantic-release, we need to fetch the tags
# TODO Is this really needed
# - name: Fetch tags
# shell: bash
# run: |
# git fetch --tags
# git clean -fd

- name: Docker login
uses: docker/login-action@v3
if: inputs.docker-user != '' && inputs.docker-password != '' && steps.release.outputs.new-release-version != ''
with:
username: ${{ inputs.docker-username }}
password: ${{ inputs.docker-password }}

- name: Set args
id: goreleaser-args
shell: bash
Expand All @@ -81,7 +88,5 @@ runs:
env:
GITHUB_TOKEN: ${{ inputs.github-token }}
GOPRIVATE: github.com/turo/
# TODO Handle the prerelease value? How can we get this out of the semantic-release output?
# This is done in the goreleaser config file with the prerelease: auto option
with:
args: release ${{ steps.goreleaser-args.outputs.args }}

0 comments on commit 848cd55

Please sign in to comment.