diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..0a9d9b8 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,32 @@ +name: Publish +on: + workflow_dispatch: +concurrency: + group: publish + cancel-in-progress: true +permissions: write-all +jobs: + publish-ghcr: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: tools/prebuild.sh + - uses: devcontainers/action@v1 + with: + publish-features: true + base-path-to-features: src + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + update-docs: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + packages: write + steps: + - uses: actions/checkout@v3 + - uses: devcontainers/action@v1 + with: + base-path-to-features: src + generate-docs: true + - uses: stefanzweifel/git-auto-commit-action@v4 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml deleted file mode 100644 index 935ef81..0000000 --- a/.github/workflows/release.yaml +++ /dev/null @@ -1,47 +0,0 @@ -name: "Release dev container features & Generate Documentation" -on: - workflow_dispatch: - -jobs: - deploy: - if: ${{ github.ref == 'refs/heads/main' }} - runs-on: ubuntu-latest - permissions: - contents: write - pull-requests: write - packages: write - steps: - - uses: actions/checkout@v3 - - - name: "Publish Features" - uses: devcontainers/action@v1 - with: - publish-features: "true" - base-path-to-features: "./src" - generate-docs: "true" - - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Create PR for Documentation - id: push_image_info - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: | - set -e - echo "Start." - # Configure git and Push updates - git config --global user.email github-actions@github.com - git config --global user.name github-actions - git config pull.rebase false - branch=automated-documentation-update-$GITHUB_RUN_ID - git checkout -b $branch - message='Automated documentation update' - # Add / update and commit - git add */**/README.md - git commit -m 'Automated documentation update [skip ci]' || export NO_UPDATES=true - # Push - if [ "$NO_UPDATES" != "true" ] ; then - git push origin "$branch" - gh pr create --title "$message" --body "$message" - fi diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml deleted file mode 100644 index 9e5f9bf..0000000 --- a/.github/workflows/test.yaml +++ /dev/null @@ -1,58 +0,0 @@ -name: "CI - Test Features" -on: - push: - branches: - - main - pull_request: - workflow_dispatch: - -jobs: - test-autogenerated: - runs-on: ubuntu-latest - continue-on-error: true - strategy: - matrix: - features: - - color - - hello - baseImage: - - debian:latest - - ubuntu:latest - - mcr.microsoft.com/devcontainers/base:ubuntu - steps: - - uses: actions/checkout@v3 - - - name: "Install latest devcontainer CLI" - run: npm install -g @devcontainers/cli - - - name: "Generating tests for '${{ matrix.features }}' against '${{ matrix.baseImage }}'" - run: devcontainer features test --skip-scenarios -f ${{ matrix.features }} -i ${{ matrix.baseImage }} . - - test-scenarios: - runs-on: ubuntu-latest - continue-on-error: true - strategy: - matrix: - features: - - color - - hello - steps: - - uses: actions/checkout@v3 - - - name: "Install latest devcontainer CLI" - run: npm install -g @devcontainers/cli - - - name: "Generating tests for '${{ matrix.features }}' scenarios" - run: devcontainer features test -f ${{ matrix.features }} --skip-autogenerated . - - test-global: - runs-on: ubuntu-latest - continue-on-error: true - steps: - - uses: actions/checkout@v3 - - - name: "Install latest devcontainer CLI" - run: npm install -g @devcontainers/cli - - - name: "Testing global scenarios" - run: devcontainer features test --global-scenarios-only . diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..41125ed --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,28 @@ +name: Test +on: + push: + branches: [main] + paths: + - src/** + - "!src/**.md" + - test/** + - .github/workflows/test.yml + pull_request: + branches: [main] + paths: + - src/** + - "!src/**.md" + - test/** + - .github/workflows/test.yml + workflow_dispatch: +concurrency: + group: test-${{ github.ref }} + cancel-in-progress: true +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: npm install -g @devcontainers/cli + # TODO: When features grow too numerous, test ONLY CHANGED features + - run: tools/test.sh diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml deleted file mode 100644 index 5dcc21b..0000000 --- a/.github/workflows/validate.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: "Validate devcontainer-feature.json files" -on: - workflow_dispatch: - pull_request: - -jobs: - validate: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - name: "Validate devcontainer-feature.json files" - uses: devcontainers/action@v1 - with: - validate-only: "true" - base-path-to-features: "./src" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dc74129 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +src/*/utils + +logs +*.log diff --git a/tools/prebuild.sh b/tools/prebuild.sh new file mode 100755 index 0000000..8e4c336 --- /dev/null +++ b/tools/prebuild.sh @@ -0,0 +1,13 @@ +#!/bin/bash +set -e + +for id in src/*; do + id=$(basename "$id") + if [[ ! -d src/$id ]]; then + echo "🟨 Skipping $id..." + continue + fi + echo "🟪 Copying utils/ to src/$id/utils/..." + rsync -a utils/ "src/$id/utils/" + echo "🟩 Copied utils/ to src/$id/utils/" +done diff --git a/tools/test.sh b/tools/test.sh new file mode 100755 index 0000000..d35b739 --- /dev/null +++ b/tools/test.sh @@ -0,0 +1,5 @@ +#!/bin/bash +set -e + +tools/prebuild.sh +devcontainer features test "$@" diff --git a/utils/clear_local_apt_index.sh b/utils/clear_local_apt_index.sh new file mode 100644 index 0000000..087c54e --- /dev/null +++ b/utils/clear_local_apt_index.sh @@ -0,0 +1,8 @@ +# shellcheck shell=bash + +clear_local_apt_index() ( + set -e + + rm -rf /var/lib/apt/lists/* + echo '🟩 Cleared local apt index' +) diff --git a/utils/ensure_apt_packages.sh b/utils/ensure_apt_packages.sh new file mode 100644 index 0000000..3d84438 --- /dev/null +++ b/utils/ensure_apt_packages.sh @@ -0,0 +1,19 @@ +# shellcheck shell=bash + +ensure_apt_packages() ( + set -e + + export DEBIAN_FRONTEND=noninteractive + if dpkg -s "$@" &>/dev/null; then + echo "🟦 $@ is already installed" + else + if [[ $(find /var/lib/apt/lists/* | wc -l) == 0 ]]; then + echo '🟪 Updating local apt index...' + apt-get update -y + echo '🟩 Updated local apt index' + fi + echo "🟪 Installing $@..." + apt-get install -y --no-install-recommends "$@" + echo "🟩 Installed $@" + fi +)