Skip to content

Commit

Permalink
Add additionalMounts for GitHub Action Output Mount (#219)
Browse files Browse the repository at this point in the history
* Update @actions/core to that state is stored via GITHUB_STATE
* Update scripts to use GITHUB_OUTPUT rather than `set-output`
* Add env var/mount for GITHUB_OUTPUT
* Add GITHUB_OUTPUT test in ci_common.yml
* Add GITHUB_ENV and GITHUB_PATH handling
* Update to various actions to fix node12 and set-state/set-output warnings

---------

Co-authored-by: Stuart Leeks <[email protected]>
  • Loading branch information
Stephen Andary and stuartleeks authored Mar 6, 2023
1 parent 73013c9 commit df4ab16
Show file tree
Hide file tree
Showing 9 changed files with 166 additions and 52 deletions.
119 changes: 90 additions & 29 deletions .github/workflows/ci_common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# This workflow contains the core logic to build, test and release the GitHub Action and Azure DevOps Task
# It is called via workflow_call from the pr-bot
#
name: 'build-test'
on:
name: "build-test"
on:
workflow_call:
inputs:
prNumber:
Expand Down Expand Up @@ -51,7 +51,6 @@ on:
required: true

jobs:

build: # run build using the github action!
runs-on: ubuntu-latest
name: build, test, package
Expand Down Expand Up @@ -84,10 +83,10 @@ jobs:
const pushOption = ${{ inputs.runFullTests }} ? 'filter' : 'never';
console.log(`Setting image_push_option=${pushOption}`);
core.setOutput("image_push_option", pushOption);
- name: Login to GitHub Container Registry
if: ${{ steps.set_image_push_option.outputs.image_push_option == 'filter' }}
uses: docker/login-action@v2
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
Expand Down Expand Up @@ -149,7 +148,7 @@ jobs:
BRANCH: ${{ github.ref }}
with:
imageName: ghcr.io/devcontainers/ci-devcontainer
imageTag: ${{ steps.set_image_tag.outputs.image_tag }}
imageTag: ${{ steps.set_image_tag.outputs.image_tag }}
runCmd: |
echo "Starting"
./scripts/build-test-package.sh
Expand Down Expand Up @@ -178,14 +177,14 @@ jobs:
with:
name: azdo-task-dev
path: ./output/devcontainers-dev.ci-${{ steps.build.outputs.version }}.vsix
if-no-files-found: error
if-no-files-found: error

- uses: actions/upload-artifact@v3
name: Create release AzDO VSIX artifact
with:
name: azdo-task
path: ./output/devcontainers.ci-${{ steps.build.outputs.version }}.vsix
if-no-files-found: error
if-no-files-found: error

checks-succeeded:
# simple no-op job to use as step for check status
Expand All @@ -206,13 +205,13 @@ jobs:
- test-platform-with-runcmd
- test-env-vars-on-post-create
- test-multiple-tags-job2
- test-github-output
runs-on: ubuntu-latest
steps:
- name: Simple step
run: |
echo Done!
pr-checks:
name: Mark PR checks as complete
needs: # TODO - check what jobs need adding here
Expand All @@ -237,7 +236,7 @@ jobs:
release:
name: Create release
runs-on: ubuntu-latest
needs:
needs:
- build
- checks-succeeded
if: ${{ inputs.release == true }}
Expand All @@ -260,7 +259,7 @@ jobs:
echo "VERSION_MAJOR=${VERSION_MAJOR}"
- name: Download release VSIX
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: azdo-task
path: output
Expand All @@ -271,7 +270,7 @@ jobs:
echo "VERSION_SHORT: $VERSION_SHORT"
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
uses: docker/login-action@v2
if: github.ref == 'refs/heads/main' # only need this for push (on `main`)
with:
registry: ghcr.io
Expand Down Expand Up @@ -323,9 +322,8 @@ jobs:
run: |
git config user.name "CI build"
git config user.email [email protected]
./scripts/gh-release.sh
./scripts/gh-release.sh
#
# Jobs to test
Expand Down Expand Up @@ -359,18 +357,18 @@ jobs:
echo "VERSION_SHORT: $VERSION_SHORT"
- name: Download workflow artifacts
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
path: output

- name: Download release VSIX
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: azdo-task-dev
path: output

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
uses: docker/login-action@v2
if: github.ref == 'refs/heads/main' # only need this for push (on `main`)
with:
registry: ghcr.io
Expand Down Expand Up @@ -416,7 +414,6 @@ jobs:
AZDO_PROJECT
AZDO_BUILD
test-simple:
name: Run simple test
runs-on: ubuntu-latest
Expand Down Expand Up @@ -473,7 +470,7 @@ jobs:

- name: Login to GitHub Container Registry
if: ${{ needs.build.outputs.image_push_option == 'filter' }}
uses: docker/login-action@v2
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
Expand Down Expand Up @@ -518,7 +515,7 @@ jobs:

- name: Login to GitHub Container Registry
if: ${{ needs.build.outputs.image_push_option == 'filter' }}
uses: docker/login-action@v2
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
Expand All @@ -540,7 +537,8 @@ jobs:
with:
subFolder: github-tests/Dockerfile/env-vars-on-post-create
imageName: ghcr.io/devcontainers/ci/tests/env-vars-on-post-create
env: | # TEST_ENV_VALUE2 is an additional env var to pass to the container
env:
| # TEST_ENV_VALUE2 is an additional env var to pass to the container
TEST_ENV_VALUE2=AdditionalEnvVar
runCmd: |
cat marker.txt
Expand Down Expand Up @@ -794,7 +792,7 @@ jobs:
uses: docker/setup-buildx-action@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
uses: docker/login-action@v2
if: ${{ needs.build.outputs.image_push_option == 'filter' }}
with:
registry: ghcr.io
Expand Down Expand Up @@ -829,7 +827,6 @@ jobs:
push
pull_request
test-compose-features:
name: Run GitHub docker-compose with features test
runs-on: ubuntu-latest
Expand Down Expand Up @@ -916,7 +913,7 @@ jobs:
ref: ${{ inputs.prRef }}

- name: Set up QEMU for multi-architecture builds
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
Expand All @@ -936,7 +933,7 @@ jobs:
sudo apt-get install skopeo
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
uses: docker/login-action@v2
if: ${{ needs.build.outputs.image_push_option == 'filter' }}
with:
registry: ghcr.io
Expand Down Expand Up @@ -983,15 +980,15 @@ jobs:
if: ${{ needs.build.outputs.image_push_option == 'filter' }}
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
persist-credentials: false
# if the following value is missing (i.e. not triggered via comment workflow)
# then the default checkout will apply
ref: ${{ inputs.prRef }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
Expand All @@ -1016,10 +1013,10 @@ jobs:
push: always

- name: Set up QEMU for multi-architecture builds
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2

- name: Install updated Skopeo
# This can be omitted once runner images have a version of Skopeo > 1.4.1
Expand Down Expand Up @@ -1081,3 +1078,67 @@ jobs:
echo "Checking tag2-${{ github.run_id }} exists... "
echo "$versions" | grep -q "tag1-${{ github.run_id }}"
echo "Tag exists."
test-github-output:
runs-on: ubuntu-latest
needs: build
steps:
- name: Checkout
uses: actions/checkout@v3
with:
persist-credentials: false
# if the following value is missing (i.e. not triggered via comment workflow)
# then the default checkout will apply
ref: ${{ inputs.prRef }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
if: ${{ needs.build.outputs.image_push_option == 'filter' }}
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}


# Published action contains compiled JS, but we need to compile it here
- uses: actions/setup-node@v3
with:
node-version: 16
- name: Compile GH action
run: |
(cd common && npm install && npm run build)
(cd github-action/ && npm install && npm run build && npm run package)
- id: github-output
name: Build and run test with GITHUB_OUTPUT
uses: ./
with:
subFolder: github-tests/Dockerfile/outputs
imageName: ghcr.io/devcontainers/ci/tests/outputs
imageTag: ${{ needs.build.outputs.image_tag }}
push: ${{ needs.build.outputs.image_push_option }}
eventFilterForPush: |
push
pull_request
runCmd: |
echo "test=hello" >> "$GITHUB_OUTPUT"
echo "test2=world" >> "$GITHUB_OUTPUT"
echo "TEST_ENV=env_value" >> "$GITHUB_ENV"
echo "/mnt/test/path" >> "$GITHUB_PATH"
- name: Validate output
run: |
set -e
echo "Test outputs..."
test "${{ steps.github-output.outputs.test }}" == "hello"
test "${{ steps.github-output.outputs.test2 }}" == "world"
echo "Test Env"
test "${TEST_ENV}" == "env_value"
echo "Test Path"
echo "${PATH}" | grep -q "/mnt/test/path"
6 changes: 3 additions & 3 deletions azdo-task/scripts/build-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ echo "VERSION_MAJOR=${VERSION_MAJOR}"
echo "VERSION_MINOR=${VERSION_MINOR}"
echo "VERSION_PATCH=${VERSION_PATCH}"

echo "::set-output name=version::$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH"
echo "::set-output name=version_short::$VERSION_MAJOR.$VERSION_MINOR"
echo "::set-output name=version_major::$VERSION_MAJOR"
echo "version=$VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH" >> "$GITHUB_OUTPUT"
echo "version_short=$VERSION_MAJOR.$VERSION_MINOR" >> "$GITHUB_OUTPUT"
echo "version_major=$VERSION_MAJOR" >> "$GITHUB_OUTPUT"

if [[ -n $set_patch_version ]]; then
echo "--set-patch-version specified. Setting extension version to $VERSION_MAJOR.$VERSION_MINOR.$VERSION_PATCH"
Expand Down
7 changes: 7 additions & 0 deletions common/__tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ describe('load', () => {
"runArgs" : [
"test1",
"test2"
],
"mounts" : [
"/mnt/test/1",
"/mnt/test/2"
]
}`;
const devcontainerConfig = loadFromString(json);
Expand All @@ -76,4 +80,7 @@ describe('load', () => {
test('runArgs to be correct', () => {
expect(devcontainerConfig.runArgs).toStrictEqual(['test1', 'test2']);
});
test('mounts to be correct', () => {
expect(devcontainerConfig.mounts).toStrictEqual(['/mnt/test/1', '/mnt/test/2']);
});
});
26 changes: 16 additions & 10 deletions common/src/dev-container-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ async function runSpecCli<T>(options: {
log: (data: string) => void;
env?: NodeJS.ProcessEnv;
}) {
let stdout = '';
const spawnOptions: SpawnOptions = {
log: data => (stdout += data),
err: data => options.log(data),
env: options.env ? {...process.env, ...options.env} : process.env,
};
const command = getSpecCliInfo().command;
console.log(`About to run ${command} ${options.args.join(' ')}`); // TODO - take an output arg to allow GH to use core.info
await spawn(command, options.args, spawnOptions);
let stdout = '';
const spawnOptions: SpawnOptions = {
log: data => (stdout += data),
err: data => options.log(data),
env: options.env ? {...process.env, ...options.env} : process.env,
};
const command = getSpecCliInfo().command;
console.log(`About to run ${command} ${options.args.join(' ')}`); // TODO - take an output arg to allow GH to use core.info
await spawn(command, options.args, spawnOptions);

return parseCliOutput<T>(stdout);
}
Expand Down Expand Up @@ -152,7 +152,7 @@ async function devContainerBuild(
args.workspaceFolder,
];
if (args.imageName) {
args.imageName.forEach(iName =>
args.imageName.forEach(iName =>
commandArgs.push('--image-name', iName),
);
}
Expand Down Expand Up @@ -190,6 +190,7 @@ export interface DevContainerCliUpArgs {
skipContainerUserIdUpdate?: boolean;
env?: string[];
userDataFolder?: string;
additionalMounts?: string[];
}
async function devContainerUp(
args: DevContainerCliUpArgs,
Expand All @@ -213,6 +214,11 @@ async function devContainerUp(
if (args.skipContainerUserIdUpdate) {
commandArgs.push('--update-remote-user-uid-default', 'off');
}
if (args.additionalMounts) {
args.additionalMounts.forEach(mount =>
commandArgs.push('--mount', mount),
);
}
return await runSpecCli<DevContainerCliUpResult>({
args: commandArgs,
log,
Expand Down
2 changes: 1 addition & 1 deletion docs/multi-platform-builds.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Checkout (GitHub)
uses: actions/checkout@v3
- name: Set up QEMU for multi-architecture builds
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v2
- name: Setup Docker buildx for multi-architecture builds
uses: docker/setup-buildx-action@v2
with:
Expand Down
Loading

0 comments on commit df4ab16

Please sign in to comment.