Skip to content

Commit

Permalink
Fix versioning in workflows (#985)
Browse files Browse the repository at this point in the history
  • Loading branch information
mburumaxwell authored Feb 17, 2024
1 parent 0d0f51c commit 7fbc18b
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 58 deletions.
19 changes: 11 additions & 8 deletions .github/workflows/extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ jobs:
fetch-depth: 0 # Required for GitVersion

- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0.10
uses: gittools/actions/gitversion/setup@v0
with:
versionSpec: '5.x'

- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/execute@v0.10
uses: gittools/actions/gitversion/execute@v0
with:
useConfigFile: true

Expand Down Expand Up @@ -70,6 +70,9 @@ jobs:
uses: cschleiden/replace-tokens@v1
with:
files: '["${{ github.workspace }}/extension/overrides*.json"]'
env:
MAJOR_MINOR_PATCH: ${{ steps.gitversion.outputs.majorMinorPatch }}
BUILD_NUMBER: ${{ github.run_number }}

- name: Update values in extension/task/task.json
run: |
Expand All @@ -82,18 +85,18 @@ jobs:
tfx extension create
--root extension
--manifest-globs vss-extension.json
--output-path $GITHUB_WORKSPACE/drop/dev
--output-path ${{ github.workspace }}/drop/dev
--json5
--overrides-file $GITHUB_WORKSPACE/extension/overrides.dev.json
--overrides-file ${{ github.workspace }}/extension/overrides.dev.json
- name: Create Extension (prod)
run: >
tfx extension create
--root extension
--manifest-globs vss-extension.json
--output-path $GITHUB_WORKSPACE/drop/prod
--output-path ${{ github.workspace }}/drop/prod
--json5
--overrides-file $GITHUB_WORKSPACE/extension/overrides.prod.json
--overrides-file ${{ github.workspace }}/extension/overrides.prod.json
- name: Publish Artifact
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -132,7 +135,7 @@ jobs:
if: github.ref == 'refs/heads/main'
run: >
tfx extension publish
--vsix $GITHUB_WORKSPACE/dev/*.vsix
--vsix ${{ github.workspace }}/dev/*.vsix
--auth-type pat
--token ${{ secrets.AZURE_DEVOPS_EXTENSION_TOKEN }}
--share-with tingle
Expand All @@ -141,6 +144,6 @@ jobs:
if: startsWith(github.ref, 'refs/tags/')
run: >
tfx extension publish
--vsix $GITHUB_WORKSPACE/prod/*.vsix
--vsix ${{ github.workspace }}/prod/*.vsix
--auth-type pat
--token ${{ secrets.AZURE_DEVOPS_EXTENSION_TOKEN }}
56 changes: 29 additions & 27 deletions .github/workflows/server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ jobs:
Build:
runs-on: ubuntu-latest
env:
buildConfiguration: 'Release'
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
IMAGE_NAME: 'dependabot-server'
DOCKER_BUILDKIT: 1 # Enable Docker BuildKit
Expand All @@ -33,12 +32,13 @@ jobs:
fetch-depth: 0 # Required for GitVersion

- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0.10
uses: gittools/actions/gitversion/setup@v0
with:
versionSpec: '5.x'

- name: Determine Version
uses: gittools/actions/gitversion/[email protected]
uses: gittools/actions/gitversion/execute@v0
id: gitversion
with:
useConfigFile: true

Expand All @@ -48,48 +48,50 @@ jobs:
dotnet-version: '8.x'

- name: Test
run: dotnet test -c $buildConfiguration --verbosity normal --collect "Code coverage"
run: dotnet test -c Release --collect "Code coverage"

- name: Publish
run: |
dotnet publish \
$GITHUB_WORKSPACE/server/Tingle.Dependabot/Tingle.Dependabot.csproj \
-c $buildConfiguration \
-o $GITHUB_WORKSPACE/drop/Tingle.Dependabot
${{ github.workspace }}/server/Tingle.Dependabot/Tingle.Dependabot.csproj \
-c Release \
-o ${{ github.workspace }}/drop/Tingle.Dependabot
- name: Replace tokens
uses: cschleiden/replace-tokens@v1
with:
files: '["${{ github.workspace }}/server/main.bicep"]'
env:
IMAGE_TAG: ${{ steps.gitversion.outputs.nuGetVersionV2 }}

- name: Build bicep file
uses: azure/CLI@v1
with:
azcliversion: 2.45.0 # somehow 2.46.0 is failing
inlineScript: |
cp $GITHUB_WORKSPACE/server/main.bicep $GITHUB_WORKSPACE/drop/main.bicep
az bicep build --file server/main.bicep --outfile $GITHUB_WORKSPACE/drop/main.json
cp ${{ github.workspace }}/server/main.bicep ${{ github.workspace }}/drop/main.bicep && \
az bicep build --file server/main.bicep --outfile ${{ github.workspace }}/drop/main.json
- name: Pull Docker base image & warm Docker cache
run: docker pull "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:latest"
run: docker pull "ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest"

- name: Build image
run: |
docker build \
-f server/Tingle.Dependabot/Dockerfile.CI \
--label com.github.image.run.id=$GITHUB_RUN_ID \
--label com.github.image.run.number=$GITHUB_RUN_NUMBER \
--label com.github.image.job.id=$GITHUB_JOB \
--label com.github.image.source.sha=$GITHUB_SHA \
--label com.github.image.source.branch=$GITHUB_REF \
-t "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:latest" \
-t "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$GITVERSION_SHORTSHA" \
-t "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$GITVERSION_NUGETVERSIONV2" \
-t "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$GITVERSION_MAJOR.$GITVERSION_MINOR" \
-t "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$GITVERSION_MAJOR" \
--cache-from ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:latest \
--label com.github.image.run.id=${{ github.run_id }} \
--label com.github.image.run.number=${{ github.run_number }} \
--label com.github.image.job.id=${{ github.job }} \
--label com.github.image.source.sha=${{ github.sha }} \
--label com.github.image.source.branch=${{ github.ref }} \
-t "ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest" \
-t "ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.gitversion.outputs.shortSha }}" \
-t "ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.gitversion.outputs.nuGetVersionV2 }}" \
-t "ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.gitversion.outputs.major}}.${{ steps.gitversion.outputs.minor }}" \
-t "ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.gitversion.outputs.major }}" \
--cache-from ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest \
--build-arg BUILDKIT_INLINE_CACHE=1 \
$GITHUB_WORKSPACE/drop/Tingle.Dependabot
${{ github.workspace }}/drop/Tingle.Dependabot
- name: Log into registry
if: ${{ (github.ref == 'refs/heads/main') || (!startsWith(github.ref, 'refs/pull')) || startsWith(github.ref, 'refs/tags') }}
Expand All @@ -98,18 +100,18 @@ jobs:
- name: Push image (latest, ShortSha)
if: ${{ (github.ref == 'refs/heads/main') || startsWith(github.ref, 'refs/tags') }}
run: |
docker push "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:latest"
docker push "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$GITVERSION_SHORTSHA"
docker push "ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest"
docker push "ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.gitversion.outputs.shortSha }}"
- name: Push image (NuGetVersionV2)
if: ${{ !startsWith(github.ref, 'refs/pull') }}
run: docker push "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$GITVERSION_NUGETVERSIONV2"
run: docker push "ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.gitversion.outputs.nuGetVersionV2 }}"

- name: Push image (major, minor)
if: startsWith(github.ref, 'refs/tags')
run: |
docker push "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$GITVERSION_MAJOR.$GITVERSION_MINOR"
docker push "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$GITVERSION_MAJOR"
docker push "ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.gitversion.outputs.major }}.${{ steps.gitversion.outputs.minor }}"
docker push "ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.gitversion.outputs.major }}"
- name: Publish Artifact
uses: actions/upload-artifact@v4
Expand Down
39 changes: 20 additions & 19 deletions .github/workflows/updater.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@ jobs:
fetch-depth: 0 # Required for GitVersion

- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0.10
uses: gittools/actions/gitversion/setup@v0
with:
versionSpec: '5.x'

- name: Determine Version
uses: gittools/actions/gitversion/[email protected]
uses: gittools/actions/gitversion/execute@v0
id: gitversion
with:
useConfigFile: true

Expand All @@ -79,7 +80,7 @@ jobs:
working-directory: updater

- name: Pull Docker base image & warm Docker cache
run: docker pull "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:latest"
run: docker pull "ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest"
# TODO: remove this after at least one release tagged 'latest'
continue-on-error: true

Expand All @@ -89,17 +90,17 @@ jobs:
-f updater/Dockerfile \
--build-arg BUILDKIT_INLINE_CACHE=1 \
--build-arg ECOSYSTEM=${{ matrix.suite.ecosystem }} \
--label com.github.image.run.id=$GITHUB_RUN_ID \
--label com.github.image.run.number=$GITHUB_RUN_NUMBER \
--label com.github.image.job.id=$GITHUB_JOB \
--label com.github.image.source.sha=$GITHUB_SHA \
--label com.github.image.source.branch=$GITHUB_REF \
-t "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:latest" \
-t "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$GITVERSION_SHORTSHA" \
-t "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$GITVERSION_NUGETVERSIONV2" \
-t "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$GITVERSION_MAJOR.$GITVERSION_MINOR" \
-t "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$GITVERSION_MAJOR" \
--cache-from ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:latest \
--label com.github.image.run.id=${{ github.run_id }} \
--label com.github.image.run.number=${{ github.run_number }} \
--label com.github.image.job.id=${{ github.job }} \
--label com.github.image.source.sha=${{ github.sha }} \
--label com.github.image.source.branch=${{ github.ref }} \
-t "ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest" \
-t "ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.gitversion.outputs.shortSha }}" \
-t "ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.gitversion.outputs.nuGetVersionV2 }}" \
-t "ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.gitversion.outputs.major}}.${{ steps.gitversion.outputs.minor }}" \
-t "ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.gitversion.outputs.major }}" \
--cache-from ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest \
.
- name: Log into registry
Expand All @@ -109,15 +110,15 @@ jobs:
- name: Push image (latest, ShortSha)
if: ${{ (github.ref == 'refs/heads/main') || startsWith(github.ref, 'refs/tags') }}
run: |
docker push "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:latest"
docker push "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$GITVERSION_SHORTSHA"
docker push "ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest"
docker push "ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.gitversion.outputs.shortSha }}"
- name: Push image (NuGetVersionV2)
if: ${{ !startsWith(github.ref, 'refs/pull') }}
run: docker push "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$GITVERSION_NUGETVERSIONV2"
run: docker push "ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.gitversion.outputs.nuGetVersionV2 }}"

- name: Push image (major, minor)
if: startsWith(github.ref, 'refs/tags')
run: |
docker push "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$GITVERSION_MAJOR.$GITVERSION_MINOR"
docker push "ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME:$GITVERSION_MAJOR"
docker push "ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.gitversion.outputs.major }}.${{ steps.gitversion.outputs.minor }}"
docker push "ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:${{ steps.gitversion.outputs.major }}"
2 changes: 1 addition & 1 deletion extension/overrides.dev.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"id":"dependabot-dev",
"version": "#{GITVERSION_MAJORMINORPATCH}#.#{GITHUB_RUN_NUMBER}#",
"version": "#{MAJOR_MINOR_PATCH}#.#{BUILD_NUMBER}#",
"name": "Dependabot (Dev)"
}
2 changes: 1 addition & 1 deletion extension/overrides.prod.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "#{GITVERSION_MAJORMINORPATCH}#.#{GITHUB_RUN_NUMBER}#",
"version": "#{MAJOR_MINOR_PATCH}#.#{BUILD_NUMBER}#",
"public": true
}
2 changes: 1 addition & 1 deletion server/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ param githubToken string = ''

@minLength(1)
@description('Tag of the docker images.')
param imageTag string = '#{GITVERSION_NUGETVERSIONV2}#'
param imageTag string = '#{IMAGE_TAG}#'

var fileShares = [
{ name: 'certs' }
Expand Down
2 changes: 1 addition & 1 deletion server/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"imageTag": {
"type": "string",
"defaultValue": "#{GITVERSION_NUGETVERSIONV2}#",
"defaultValue": "#{IMAGE_TAG}#",
"minLength": 1,
"metadata": {
"description": "Tag of the docker images."
Expand Down

0 comments on commit 7fbc18b

Please sign in to comment.