Skip to content

Commit 071c369

Browse files
committed
Fork off the get-azure-pipelines-artifact Action
Much of what the `setup-git-for-windows-sdk` Action does is to download an artifact (in a robust fashion, retrying a couple times if necessary) and caching it. This is useful for other things, too. Let's transmogrify the Action that is rather specific for Git for Windows' use case to allow downloading arbitrary artifacts from arbitrary Azure Pipelines. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent b8a77eb commit 071c369

File tree

10 files changed

+159
-330
lines changed

10 files changed

+159
-330
lines changed

.github/workflows/test.yml

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on: # rebuild any PRs and main branch changes
1010

1111
jobs:
1212
build: # make sure build/ci work properly
13-
runs-on: windows-latest
13+
runs-on: ubuntu-latest
1414
steps:
1515
- uses: actions/checkout@v2
1616
- run: npm ci
@@ -27,30 +27,14 @@ jobs:
2727
exit 1
2828
}
2929
test: # make sure the action works on a clean machine without building
30-
runs-on: windows-latest
30+
runs-on: ubuntu-latest
3131
steps:
3232
- uses: actions/checkout@v2
3333
- name: Run this Action in-place
3434
uses: ./
35-
- name: Verify that the Bash of Git for Windows' SDK is used
35+
with:
36+
repository: git/git
37+
definitionId: 10
38+
- name: Verify that the package was downloaded
3639
shell: bash
37-
run: |
38-
set -x
39-
echo "This is the MSYS2 pseudo root: $(cygpath -aw /)"
40-
test "gcc is /mingw64/bin/gcc" = "$(type gcc)"
41-
test "prove is /usr/bin/core_perl/prove" = "$(type prove)"
42-
prove -V
43-
printf '%s\n' \
44-
"#include <stdio.h>" \
45-
'' \
46-
'int main()' \
47-
'{' \
48-
' printf("Hello, world!\n");' \
49-
' return 0;' \
50-
'}' >hello-world.c
51-
gcc -o hello-world.exe hello-world.c
52-
hello="$(./hello-world.exe)"
53-
test 'Hello, world!' = "$hello"
54-
55-
# Verify that the locale is set, enabling `grep -P` to work
56-
test 123 = "$(printf '1248\n123\n' | grep -P '2(?!4)')"
40+
run: test -f sparse/sparse_*.deb

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,5 @@ Thumbs.db
9898
__tests__/runner/*
9999
lib/**/*
100100

101-
# Ignore downloaded 64-bit minimal SDK
102-
/git-sdk-64-minimal/
101+
# Ignore downloaded artifact
102+
/sparse_*.deb

.vscode/settings.json

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
{
22
"cSpell.ignoreRegExpList": [
3-
"CHERE_INVOKING",
4-
"LC_CTYPE",
5-
"SDK's",
6-
"makepkg-git",
7-
"mingw-w64-git",
8-
"mingw32",
9-
"mingw64",
3+
"INPUT_DEFINITIONID",
4+
"arrowParens",
105
"vstfs://.*"
116
],
127
"cSpell.words": [
138
"Backoff",
14-
"MSYSTEM",
15-
"Pacman",
169
"autodrain",
10+
"dpkg",
11+
"refname",
1712
"unzipper",
1813
"vercel"
1914
],

README.md

Lines changed: 26 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,61 @@
1-
# Set up a Git for Windows SDK (or a subset thereof)
1+
# Download an artifact from an Azure Pipeline
22

3-
Use this Action to initialize an environment to develop Git for Windows.
3+
Use this Action to download an artifact from an Azure Pipeline.
44

55
## Getting Started
66

77
```yaml
8-
name: Build stuff in Git for Windows' SDK
8+
name: Download stuff from an Azure Pipeline
99
on: [push]
1010
jobs:
1111
build:
12-
runs-on: windows-latest
12+
runs-on: ubuntu-16.04
1313
steps:
14-
- uses: actions/checkout@v2
15-
- name: Setup Git for Windows' minimal SDK
16-
uses: git-for-windows/setup-git-for-windows-sdk@v1
17-
- name: Build
18-
shell: bash
19-
run: make
14+
- name: Download a build artifact from an Azure Pipeline
15+
uses: git-for-windows/get-azure-pipelines-artifact@v0
16+
with:
17+
repository: git/git
18+
definitionId: 10
19+
artifact: sparse
20+
- run: sudo dpkg -i sparse_*.deb
2021
```
2122
2223
## Input parameters
2324
24-
### Available flavors
25+
### Repository
2526
26-
This Action supports several flavors (read: subsets) of the Git for Windows SDK that can be configured like this:
27+
This Action needs to know in which repository the artifact lives. Example: [https://dev.azure.com/git/git/_build](https://dev.azure.com/git/git/_build) shows the Azure Pipelines of the `git/git` repository. It can be configured like this:
2728

2829
```yaml
29-
- uses: git-for-windows/setup-git-for-windows-sdk
30+
- uses: git-for-windows/get-azure-pipelines-artifact@v0
3031
with:
31-
flavor: build-installers
32+
repository: git/git
3233
```
3334

34-
The supported flavors are:
35+
### Pipeline definition ID
3536

36-
- `minimal`:
37-
38-
This is the most useful flavor to build Git for Windows' source code and run its own test suite. Only available for x86_64.
39-
40-
- `makepkg-git`:
41-
42-
This flavor allows packaging `mingw-w64-git`, the Pacman package. It is only available for x86_64 but can be used to "cross-compile" for i686.
43-
44-
- `build-installers`:
45-
46-
In addition to building `mingw-w64-git`, this flavor allows bundling Git for Windows' artifacts such as the installer and the Portable Git.
47-
48-
- `full`:
49-
50-
This is the "full" SDK, [as users would install it](https://gitforwindows.org/#download-sdk), with a pre-selected set of packages pre-installed. Additional packages can be installed via `pacman -S <package>`.
51-
52-
### CPU architecture support
53-
54-
Git for Windows SDK comes in variants targeting `x86_64` (AKA "64-bit") and `i686` (AKA 32-bit). The default is `x86_64` and can be overridden like this:
37+
Every Azure Pipeline has a numerical identifier that is part of the URL. For example, the "Build sparse for Ubuntu" Pipeline in `git/git` at [https://dev.azure.com/git/git/_build?definitionId=10](https://dev.azure.com/git/git/_build?definitionId=10) has the identifier `10`. It needs to be configured via the `definitionId` key.
5538

5639
```yaml
57-
- uses: git-for-windows/setup-git-for-windows-sdk
40+
- uses: git-for-windows/get-azure-pipelines-artifact@v0
5841
with:
59-
flavor: build-installers
60-
architecture: i686
42+
definitionId: 10
6143
```
6244

63-
Please note that only the `build-installers` and the `full` flavors are available for `i686`.
45+
### Artifact name
6446

65-
### Verbosity
47+
Pipelines can have an arbitrary number of artifacts, which are identified by a name. The `artifact` parameter specifies which one to download. It can be omitted if the given Pipeline run has only one artifact attached to it.
6648

67-
By default, this Action prints a line whenever 250 items were extracted (this does not work for the `full` flavor, where this Action is silent by default). It can be overridden by setting the input parameter `verbose`; setting it to a number will show updates whenever that many items were extracted. Setting it to `false` will suppress progress updates. Setting it to `true` will print every extracted file (this also works for the `full` flavor).
49+
### Output location
50+
51+
By default, the artifact files will be stored in the current directory. The `path` parameter can be used to override that.
52+
53+
This directory needs to be unless caching is turned off.
6854

6955
### Caching
7056

7157
To accelerate this Action, artifacts are cached once downloaded. This can be turned off by setting the input parameter `cache` to `false`.
7258

73-
In practice, caching the `full` artifacts does not provide much of a speed-up. Instead, it slows it down by adding several minutes during with the artifact is cached. Therefore, caching is disabled for the `full` artifacts by default, corresponding to `cache: auto`.
74-
7559
## Developing _this_ Action
7660

7761
> First, you'll need to have a reasonably modern version of `node` handy, such as Node 12.
@@ -92,26 +76,4 @@ Run the tests :heavy_check_mark:
9276

9377
```bash
9478
$ npm test
95-
96-
> setup-git-for-windows-sdk@0.0.0 test C:\Users\me\setup-git-for-windows-sdk
97-
> jest
98-
99-
PASS __tests__/main.test.ts (28.869 s)
100-
√ skipping tests requiring network access (224 ms)
101-
102-
console.log
103-
If you want to run tests that access the network, set:
104-
export RUN_NETWORK_TESTS=true
105-
106-
at __tests__/main.test.ts:26:13
107-
108-
PASS __tests__/downloader.test.ts (29.889 s)
109-
√ can obtain build ID (9 ms)
110-
111-
Test Suites: 2 passed, 2 total
112-
Tests: 2 passed, 2 total
113-
Snapshots: 0 total
114-
Time: 31.11 s
115-
Ran all test suites.
116-
...
11779
```

__tests__/downloader.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ test('can obtain build ID', async () => {
4949
mocked(fetch).mockReturnValue(
5050
Promise.resolve(new Response(JSON.stringify(buildIdResponse)))
5151
)
52-
const {id} = await get('minimal', 'x86_64')
52+
const {cacheId} = await get('git-for-windows/git', '22', 'git-sdk-64-minimal')
5353
expect(fetch).toHaveBeenCalledTimes(1)
54-
expect(id).toEqual('git-sdk-64-minimal-71000')
54+
expect(cacheId).toEqual('git-for-windows/git-22-git-sdk-64-minimal-71000')
5555
})

__tests__/main.test.ts

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable no-console */
2-
import {statSync} from 'fs'
2+
import fs from 'fs'
33
import * as process from 'process'
44
import * as child_process from 'child_process'
55
import * as path from 'path'
@@ -28,35 +28,28 @@ if (process.env.RUN_NETWORK_TESTS !== 'true') {
2828
)
2929
})
3030
} else {
31-
// shows how the runner will run a javascript action with env / stdout protocol
32-
test('cannot download 32-bit minimal SDK', async () => {
33-
expect(
34-
await runAction({
35-
env: {
36-
INPUT_FLAVOR: 'minimal',
37-
INPUT_ARCHITECTURE: 'i686'
38-
}
39-
})
40-
).toEqual(1)
41-
})
42-
4331
jest.setTimeout(5 * 60 * 1000) // this can easily take a minute or five
4432

45-
test('extract the 64-bit minimal SDK', async () => {
46-
const outputDirectory = `${__dirname}/../git-sdk-64-minimal`
33+
test('download `sparse` artifact', async () => {
34+
const getSparsePackages = async (): Promise<string[]> => {
35+
const files = await fs.promises.readdir('.')
36+
return files.filter(e => e.match(/^sparse_.*\.deb$/))
37+
}
38+
39+
for (const sparsePackage of await getSparsePackages()) {
40+
await fs.promises.rm(sparsePackage)
41+
}
42+
4743
expect(
4844
await runAction({
4945
env: {
50-
INPUT_FLAVOR: 'minimal',
51-
INPUT_ARCHITECTURE: 'x86_64',
52-
INPUT_PATH: outputDirectory,
53-
INPUT_VERBOSE: '250',
46+
INPUT_REPOSITORY: 'git/git',
47+
INPUT_DEFINITIONID: '10',
48+
INPUT_VERBOSE: 'true',
5449
INPUT_CACHE: 'true'
5550
}
5651
})
5752
).toEqual(0)
58-
expect(
59-
statSync.bind(null, `${outputDirectory}/mingw64/bin/gcc.exe`)
60-
).not.toThrow()
53+
expect(await getSparsePackages()).toHaveLength(1)
6154
})
6255
}

action.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
name: 'Setup Git for Windows SDK'
2-
description: 'Set up an environment to develop Git for Windows'
1+
name: 'Download an artifact from an Azure Pipeline'
2+
description: 'Download an artifact from an Azure Pipeline'
33
author: 'Johannes Schindelin'
44
branding:
55
icon: fast-forward
66
color: blue
77
inputs:
8-
flavor:
8+
repository:
9+
required: true
10+
description: 'The repository in which the Azure Pipeline lives'
11+
definitionId:
12+
required: true
13+
description: 'The identifier of the Azure Pipeline'
14+
artifact:
915
required: false
10-
description: 'The subset (if any) of the SDK: minimal, makepkg-git, build-installers, or full'
11-
default: 'minimal'
12-
architecture:
13-
required: false
14-
description: 'The architecture of the SDK: x86_64 or i686'
15-
default: 'x86_64'
16+
description: 'The name of the Azure Pipeline artifact'
1617
path:
1718
required: false
18-
description: 'Where to write the SDK files'
19-
default: ''
19+
description: 'Where to write the artifact file(s)'
2020
verbose:
2121
required: false
2222
description: 'Whether to log files as they are extracted'
2323
default: '250'
2424
cache:
2525
required: false
2626
description: 'Use @actions/cache to accelerate this Action'
27-
default: 'auto'
27+
default: 'true'
2828
runs:
2929
using: 'node12'
3030
main: 'dist/index.js'

0 commit comments

Comments
 (0)