File: release-staging.yml

package info (click to toggle)
cloc 2.08-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,304 kB
  • sloc: perl: 30,693; cpp: 1,219; python: 623; ansic: 334; asm: 267; makefile: 244; sh: 186; sql: 144; java: 136; ruby: 111; cs: 104; xml: 61; pascal: 52; lisp: 50; cobol: 35; haskell: 35; f90: 35; objc: 25; php: 22; javascript: 15; fortran: 9; ml: 8; tcl: 2
file content (171 lines) | stat: -rw-r--r-- 7,600 bytes parent folder | download
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
name: Build Windows executable

on:
  pull_request:
    types: [labeled]

jobs:
  staging_build:
    if: ${{ github.event.label.name == 'release-ready' }}
    runs-on: windows-latest

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          ref: ${{ github.head_ref }}

      # Branch name must be in the format "release-vX.XX"
      - name: Extract version from branch name
        id: get_version
        shell: pwsh
        run: |
          $branch = "${{ github.head_ref }}"
          if (-not $branch) { $branch = "${{ github.ref }}" }
          if ($branch -match 'release-v(?<ver>[0-9]+\.[0-9]+)') {
            $ver = $Matches["ver"]
            echo "VERSION_NUM=$ver" >> $env:GITHUB_OUTPUT
            echo "DISPLAY_VERSION=v$ver" >> $env:GITHUB_OUTPUT
            Write-Host "Extracted version: $ver"
          }
          else {
            Write-Error "Branch name does not match expected format (release-vX.XX)."
          }

      - name: Update version in cloc files
        shell: pwsh
        run: |
          $ver = "${{ steps.get_version.outputs.VERSION_NUM }}"
          Write-Host "Updating version in cloc and Unix/cloc to '$ver'"
          $replaceVer = 'my $VERSION = "' + $ver + '";'
          (Get-Content cloc) -replace 'my \$VERSION = ".*";', $replaceVer | Set-Content cloc
          (Get-Content Unix/cloc) -replace 'my \$VERSION = ".*";', $replaceVer | Set-Content Unix/cloc

      - name: Update README.md with version and date
        shell: pwsh
        run: |
          $ver = "${{ steps.get_version.outputs.VERSION_NUM }}"
          $disp = "${{ steps.get_version.outputs.DISPLAY_VERSION }}"
          $currentDate = (Get-Date).ToString("MMM. d, yyyy")
          Write-Host "Updating README.md with version $disp and date $currentDate"
          (Get-Content README.md) `
            -replace 'Latest release:\s+v\d+\.\d+\s+\(.*\)', "Latest release:  $disp ($currentDate)" `
            -replace 'badge/version-\d+\.\d+', "badge/version-$ver" `
            -replace 'cloc-\d+\.\d+\.pl', "cloc-$ver.pl" `
            -replace 'cloc-\d+\.\d+\.exe(?!:)', "cloc-$ver.exe" `
            -replace 'pp -M Win32::LongPath -M Encode::Unicode -M Digest::MD5 -c -x -o cloc-\d+\.\d+\.exe', "pp -M Win32::LongPath -M Encode::Unicode -M Digest::MD5 -c -x -o cloc-$ver.exe" `
            -replace '<tt>cloc-\d+\.\d+\.exe</tt>', "<tt>cloc-$ver.exe</tt>" | Set-Content README.md
      
      - name: Install or upgrade Strawberry Perl
        shell: pwsh
        run: |
          if (Get-Command perl -ErrorAction SilentlyContinue) {
            # see https://github.com/StrawberryPerl/Perl-Dist-Strawberry/issues/19#issuecomment-2401043349
            choco uninstall strawberryperl -y
          }
          choco install strawberryperl --no-progress -y
          perl -V
          cpan -v

      - name: Install CPAN dependencies
        shell: pwsh
        run: |
          cpan -i App::cpanminus
          cpanm Digest::MD5
          cpanm Regexp::Common
          cpanm Algorithm::Diff
          cpanm PAR::Packer
          cpanm Win32::LongPath || cpanm -n Win32::LongPath
      
      - name: Build executable
        shell: pwsh
        run: |
          $ver = "${{ steps.get_version.outputs.VERSION_NUM }}"
          pp -M Win32::LongPath -M Encode::Unicode -M Digest::MD5 -c -x -o "cloc-$ver.exe" cloc

      - name: Upload executable to VirusTotal and get analysis URL
        id: vt_upload
        shell: pwsh
        run: |
          $ver = "${{ steps.get_version.outputs.VERSION_NUM }}"
          $apiKey = "${{ secrets.VIRUSTOTAL_API_KEY }}"
          $exeFile = "cloc-$ver.exe"
          $absoluteFilePath = (Get-Location).Path + "\" + $exeFile
          Write-Host "Uploading $absoluteFilePath to VirusTotal..."
          $headers=@{}
          $headers.Add("accept", "application/json")
          $headers.Add("content-type", "multipart/form-data")
          $headers.Add("x-apikey", $apiKey)
          $response = Invoke-RestMethod -Uri "https://www.virustotal.com/api/v3/files" `
                                     -Method POST `
                                     -Headers $headers `
                                     -Form @{ file = Get-Item -Path $absoluteFilePath }
          $vtAnalysisId = $response.data.id
          $response2 = Invoke-WebRequest -Uri "https://www.virustotal.com/api/v3/analyses/$vtAnalysisId" -Method GET -Headers $headers
          $vtId = ($response2.Content | ConvertFrom-Json).data.links.item.Split("/")[-1]
          $vtUrl = "https://www.virustotal.com/gui/file/$vtId"
          echo "VT_URL=$vtUrl" >> $env:GITHUB_OUTPUT
          Write-Host "VirusTotal analysis available at $vtUrl"
      
      - name: Upload artifact
        uses: actions/upload-artifact@v4
        id: upload-artifact
        with:
          name: cloc-${{ steps.get_version.outputs.VERSION_NUM }}-executable
          path: cloc-${{ steps.get_version.outputs.VERSION_NUM }}.exe

      - name: Post comment with artifact and VirusTotal URL
        uses: peter-evans/create-or-update-comment@v4
        with:
          issue-number: ${{ github.event.pull_request.number }}
          body: |
            **Built executable artifact:**
            [Download the executable artifact from this workflow run](${{ steps.upload-artifact.outputs.artifact-url }})

            **VirusTotal Analysis:** ${{ steps.vt_upload.outputs.VT_URL }}

      - name: Clean up local exe
        shell: pwsh
        run: |
          $ver = "${{ steps.get_version.outputs.VERSION_NUM }}"
          Remove-Item "cloc-$ver.exe"

      - name: Update README recent versions entry
        shell: pwsh
        run: |
          $ver = "${{ steps.get_version.outputs.VERSION_NUM }}"
          $vtUrl = "${{ steps.vt_upload.outputs.VT_URL }}"
          $readme = Get-Content README.md -Raw
          $pattern = 'The entries for recent versions are:\s*\r?\n\s*\r?\n'
          $replacement = "The entries for recent versions are:`n`ncloc-$ver.exe:`n$vtUrl`n`n"
          $newReadme = [regex]::Replace($readme, $pattern, $replacement)
          Set-Content -Path README.md -Value $newReadme
          (Get-Content README.md -Raw) -replace '\r?\n\s*\r?\n$', "" | Set-Content README.md

      - name: Update Unix/NEWS with release notes
        shell: pwsh
        run: |
          $ver = "${{ steps.get_version.outputs.VERSION_NUM }}"
          $currentDate = (Get-Date).ToString("MMM. d, yyyy")
          $event = Get-Content $env:GITHUB_EVENT_PATH -Raw | ConvertFrom-Json
          $prBody = $event.pull_request.body -replace '"', '`"'
          $processedNotes = $prBody -replace '- ', '    o ' -replace '[\*\`_]', ''
          $newsContent = Get-Content Unix/NEWS -Raw -Encoding UTF8
          $header = @(
            "                Release Notes for cloc version $ver",
            "                   https://github.com/AlDanial/cloc",
            "                             $currentDate"
          )
          $newNews = $header + "" + $processedNotes + "" + ("=" * 76) + $newsContent
          Set-Content -Path Unix/NEWS -Value $newNews -Encoding UTF8
          (Get-Content Unix/NEWS -Raw) -replace '\r?\n\s*\r?\n$', "" | Set-Content Unix/NEWS -Encoding UTF8

      - name: Commit changes
        shell: pwsh
        run: |
          $ver = "${{ steps.get_version.outputs.VERSION_NUM }}"
          git config user.name "github-actions"
          git config user.email "actions@github.com"
          git add cloc README.md Unix/NEWS Unix/cloc
          git commit -m "chore: prepare release version $ver"
          git push