Skip to content

Commit 9a69a54

Browse files
committed
Use Go style pseudo-versions when there is no semver supplied details.
See crossplane/function-template-go#38. Signed-off-by: Nic Cope <nicc@rk0n.org>
1 parent 4bb9201 commit 9a69a54

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

.github/workflows/ci.yml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,22 @@ env:
1717
GO_VERSION: '1.21.3'
1818
GOLANGCI_VERSION: 'v1.54.2'
1919
DOCKER_BUILDX_VERSION: 'v0.11.2'
20+
21+
# These environment variables are important to the Crossplane CLI install.sh
22+
# script. They determine what version it installs.
2023
XP_CHANNEL: master # TODO(negz): Pin to stable once v1.14 is released.
2124
XP_VERSION: current # TODO(negz): Pin to a version once v1.14 is released.
2225

23-
# Common users. We can't run a step 'if secrets.USR != ""' but we can run
24-
# a step 'if env.USR' != ""', so we copy these to succinctly test whether
25-
# credentials have been provided before trying to run steps that need them.
26+
# This CI job will automatically push new builds to xpkg.upbound.io if the
27+
# XPKG_ACCESS_ID and XPKG_TOKEN secrets are set in the GitHub respository (or
28+
# organization) settings. Create a token at https://accounts.upbound.io.
2629
XPKG_ACCESS_ID: ${{ secrets.XPKG_ACCESS_ID }}
2730

28-
# The package to push, without a version tag.
31+
# The package to push, without a version tag. The default matches GitHub. For
32+
# example xpkg.upbound.io/crossplane/function-template-go.
2933
XPKG: xpkg.upbound.io/${{ github.repository}}
34+
35+
# The package version to push. The default is 0.0.0-gitsha.
3036
XPKG_VERSION: ${{ inputs.version }}
3137

3238
jobs:
@@ -61,6 +67,10 @@ jobs:
6167
- name: Run Unit Tests
6268
run: go test -v -cover ./...
6369

70+
# We want to build most packages for the amd64 and arm64 architectures. To
71+
# speed this up we build single-platform packages in parallel. We then upload
72+
# those packages to GitHub as a build artifact. The push job downloads those
73+
# artifacts and pushes them as a single multi-platform package.
6474
build:
6575
runs-on: ubuntu-22.04
6676
strategy:
@@ -84,6 +94,8 @@ jobs:
8494
- name: Checkout
8595
uses: actions/checkout@v4
8696

97+
# We ask Docker to use GitHub Action's native caching support to speed up
98+
# the build, per https://docs.docker.com/build/cache/backends/gha/.
8799
- name: Build Runtime
88100
id: image
89101
uses: docker/build-push-action@v5
@@ -111,6 +123,9 @@ jobs:
111123
if-no-files-found: error
112124
retention-days: 1
113125

126+
# This job downloads the single-platform packages built by the build job, and
127+
# pushes them as a multi-platform package. We only push the package it the
128+
# XPKG_ACCESS_ID and XPKG_TOKEN secrets were provided.
114129
push:
115130
runs-on: ubuntu-22.04
116131
needs:
@@ -137,10 +152,12 @@ jobs:
137152
password: ${{ secrets.XPKG_TOKEN }}
138153

139154
# If a version wasn't explicitly passed as a workflow_dispatch input we
140-
# default to version v0.0.0-shortsha, for example v0.0.0-8ed5691.
155+
# default to version v0.0.0-<git-commit-date>-<git-short-sha>, for example
156+
# v0.0.0-20231101115142-1091066df799. This is a simple implementation of
157+
# Go's pseudo-versions: https://go.dev/ref/mod#pseudo-versions.
141158
- name: Set Default Multi-Platform Package Version
142159
if: env.XPKG_VERSION == ''
143-
run: echo "XPKG_VERSION=v0.0.0-$(git rev-parse --short HEAD)" >> $GITHUB_ENV
160+
run: echo "XPKG_VERSION=v0.0.0-$(date -d@$(git show -s --format=%ct) +%Y%m%d%H%M%S)-$(git rev-parse --short=12 HEAD)" >> $GITHUB_ENV
144161

145162
- name: Push Multi-Platform Package to Upbound
146163
if: env.XPKG_ACCESS_ID != ''

0 commit comments

Comments
 (0)