-
-
Notifications
You must be signed in to change notification settings - Fork 86
120 lines (100 loc) · 4.5 KB
/
tag-and-release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Workflow file for AzureHunter v1.3.7
name: CI
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
pull_request:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# (1) First retrieve the tag for this version using gitversion
retrieve-git-version:
runs-on: ubuntu-latest
outputs:
GitVersionMajor: ${{ steps.gitversion.outputs.Major }}
GitVersionMinor: ${{ steps.gitversion.outputs.Minor }}
GitVersionPatch: ${{ steps.gitversion.outputs.Patch }}
GitVersionSemVer: ${{ steps.gitversion.outputs.SemVer }}
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v1
- name: Fetch tags for GitVersion
run: git fetch --tags
- name: Fetch master for GitVersion
if: github.ref != 'refs/heads/main'
run: git branch --create-reflog main origin/main
- name: Run GitVersion
id: gitversion # step id used as reference for output values
uses: darkquasar/[email protected]
- name: Output GitVersion values
run: |
echo "Major: ${{ steps.gitversion.outputs.Major }}"
echo "Minor: ${{ steps.gitversion.outputs.Minor }}"
echo "Patch: ${{ steps.gitversion.outputs.Patch }}"
echo "SemVer: ${{ steps.gitversion.outputs.SemVer }}"
# Let's tag the latest commit according to GitVersion output
tag-latest-commit:
# The type of runner that the job will run on
runs-on: ubuntu-latest
needs: [retrieve-git-version]
if: "contains(github.event.head_commit.message, '+tag')"
outputs:
LatestTag: ${{ steps.FetchLatestTagToVariable.outputs.LatestTag }}
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: tvdias/[email protected]
with:
repo-token: ${{ secrets.GHTOKEN }}
tag: "${{ needs.retrieve-git-version.outputs.GitVersionSemVer }}"
- name: Get Latest Tag into Output Variable
id: FetchLatestTagToVariable
env:
LatestTagEnv: ${{ needs.retrieve-git-version.outputs.GitVersionSemVer }}
run: echo "::set-output name=LatestTag::$LatestTagEnv"
# Second, create a release and publish to PowershellGallery if so indicated in commit message
# Note: I should cache the build directory and restore in a posterior job to decouple this step
create-release:
# The type of runner that the job will run on
runs-on: windows-latest
needs: [tag-latest-commit]
if: always() && (contains(github.event.head_commit.message, '+release') || (needs.tag-latest-commit.result == 'failure'))
outputs:
GitVersionMajor: ${{ steps.build_module.outputs.BuildModuleRoot }}
steps:
- uses: actions/checkout@v2
- name: Fetch tags for GitVersion
run: git fetch --tags
- name: Fetch master for GitVersion
if: github.ref != 'refs/heads/main'
run: git branch --create-reflog main origin/main
# Invoke our wrapper around Invoke-Build
# We must install GitVersion since it's used by some Build Tasks via Powershell InvokeBuild
- name: Build Module
id: build_module
env:
GitVersionTag: ${{ needs.tag-latest-commit.outputs.LatestTag }}
run: |
Write-Host "GitVersion Environment Variable: $env:GitVersionTag"
choco install -y GitVersion.Portable --force --no-progress
.\BuildModule.ps1 -BuildTask "Default"
- name: Output BuildModuleDir
run: |
echo "BuildModuleDir: ${{ steps.build_module.outputs.BuildModuleRoot }}"
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: "${{ needs.tag-latest-commit.outputs.LatestTag }}"
token: ${{ secrets.GHTOKEN }}
files: "./Output/Release/*.zip"
- name: Publish to PowershellGallery
env:
PSGalleryNugetAPIKey: "${{ secrets.NUGETAPIKEY }}"
if: "contains(github.event.head_commit.message, '+publish')"
run: .\BuildModule.ps1 -BuildTask "PublishModule"