diff --git a/.github/ghaction-docker-meta.png b/.github/ghaction-docker-meta.png new file mode 100644 index 0000000..8c33855 Binary files /dev/null and b/.github/ghaction-docker-meta.png differ diff --git a/.github/labels.yml b/.github/labels.yml new file mode 100644 index 0000000..3444025 --- /dev/null +++ b/.github/labels.yml @@ -0,0 +1,77 @@ +## more info https://github.com/crazy-max/ghaction-github-labeler +- # automerge + name: ":bell: automerge" + color: "8f4fbc" + description: "" +- # bot + name: ":robot: bot" + color: "69cde9" + description: "" +- # bug + name: ":bug: bug" + color: "b60205" + description: "" +- # dependencies + name: ":game_die: dependencies" + color: "0366d6" + description: "" +- # documentation + name: ":memo: documentation" + color: "c5def5" + description: "" +- # duplicate + name: ":busts_in_silhouette: duplicate" + color: "cccccc" + description: "" +- # enhancement + name: ":sparkles: enhancement" + color: "0054ca" + description: "" +- # feature request + name: ":bulb: feature request" + color: "0e8a16" + description: "" +- # feedback + name: ":mega: feedback" + color: "03a9f4" + description: "" +- # future maybe + name: ":rocket: future maybe" + color: "fef2c0" + description: "" +- # good first issue + name: ":hatching_chick: good first issue" + color: "7057ff" + description: "" +- # help wanted + name: ":pray: help wanted" + color: "4caf50" + description: "" +- # hold + name: ":hand: hold" + color: "24292f" + description: "" +- # invalid + name: ":no_entry_sign: invalid" + color: "e6e6e6" + description: "" +- # maybe bug + name: ":interrobang: maybe bug" + color: "ff5722" + description: "" +- # needs more info + name: ":thinking: needs more info" + color: "795548" + description: "" +- # question + name: ":question: question" + color: "3f51b5" + description: "" +- # upstream + name: ":eyes: upstream" + color: "fbca04" + description: "" +- # wontfix + name: ":coffin: wontfix" + color: "ffffff" + description: "" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..98696a7 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,82 @@ +name: ci + +on: + schedule: + - cron: '0 10 * * 0' # everyday sunday at 10am + push: + branches: + - '**' + tags: + - 'v*.*.*' + pull_request: + +env: + DOCKER_IMAGE: localhost:5000/name/app + +jobs: + multi-images: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v2.3.3 + - + name: Docker meta + id: docker_meta + uses: ./ + with: + images: | + ${{ env.DOCKER_IMAGE }} + ghcr.io/name/app + tag-sha: true + + docker-push: + runs-on: ubuntu-latest + services: + registry: + image: registry:2 + ports: + - 5000:5000 + steps: + - + name: Checkout + uses: actions/checkout@v2.3.3 + - + name: Docker meta + id: docker_meta + uses: ./ + with: + images: | + ${{ env.DOCKER_IMAGE }} + tag-sha: true + - + name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + with: + driver-opts: network=host + - + name: Build and push to local registry + uses: docker/build-push-action@v2 + with: + context: ./test + file: ./test/Dockerfile + platforms: linux/amd64,linux/arm64,linux/386 + push: true + tags: ${{ steps.docker_meta.outputs.tags }} + labels: ${{ steps.docker_meta.outputs.labels }} + - + name: Inspect image + run: | + docker pull ${{ env.DOCKER_IMAGE }}:${{ steps.docker_meta.outputs.version }} + docker image inspect ${{ env.DOCKER_IMAGE }}:${{ steps.docker_meta.outputs.version }} + - + name: Check manifest + run: | + docker buildx imagetools inspect ${{ env.DOCKER_IMAGE }}:${{ steps.docker_meta.outputs.version }} + - + name: Dump context + if: always() + uses: crazy-max/ghaction-dump-context@v1 diff --git a/.github/workflows/labels.yml b/.github/workflows/labels.yml new file mode 100644 index 0000000..08d5675 --- /dev/null +++ b/.github/workflows/labels.yml @@ -0,0 +1,20 @@ +name: labels + +on: + push: + branches: + - 'master' + paths: + - '.github/labels.yml' + - '.github/workflows/labels.yml' + +jobs: + labeler: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v2.3.3 + - + name: Run Labeler + uses: crazy-max/ghaction-github-labeler@v3.1.0 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..1fd782c --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,53 @@ +name: test + +on: + push: + branches: + - 'master' + - 'releases/v*' + paths-ignore: + - '**.md' + pull_request: + paths-ignore: + - '**.md' + +jobs: + test-containerized: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v2.3.3 + - + name: Validate + run: docker buildx bake validate + - + name: Test + run: docker buildx bake test + + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + - macOS-latest + - windows-latest + steps: + - + name: Checkout + uses: actions/checkout@v2.3.3 + - + name: Install + run: yarn install + - + name: Test + run: yarn run test + - + name: Upload coverage + uses: codecov/codecov-action@v1.0.13 + if: success() + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: ./coverage/clover.xml diff --git a/Dockerfile b/Dockerfile index 49a7366..6998ab8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,6 +20,7 @@ FROM base AS build RUN yarn build FROM deps AS test +COPY . . RUN yarn run test FROM base AS run-format diff --git a/README.md b/README.md index 2a9afcf..70c59d1 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,8 @@ GitHub Action to extract metadata (tags, labels) for Docker. This action is part If you are interested, [check out](https://git.io/Je09Y) my other :octocat: GitHub Actions! +![Screenshot](.github/ghaction-docker-meta.png) + ___ * [Features](#features) @@ -25,7 +27,7 @@ ___ ## Features -* Docker tags generated through GitHub action event and Git metadata +* Docker tags generated from GitHub action event and Git metadata * [OCI Image Format Specification](https://github.com/opencontainers/image-spec/blob/master/annotations.md) used to generate Docker labels ## Usage @@ -104,7 +106,7 @@ Following inputs can be used as `step.with` keys |---------------------|----------|------------------------------------| | `images` | List/CSV | List of Docker images to use as base name for tags | | `tag-sha` | Bool | Add git short SHA as Docker tag (default `false`) | -| `tag-edge` | String | Branch that will be tagged as edge (default `${{ repo.default_branch }}` | +| `tag-edge` | String | Branch that will be tagged as edge (default `repo.default_branch`) | | `sep-tags` | String | Separator to use for tags output (default `\n`) | | `sep-labels` | String | Separator to use for labels output (default `\n`) | diff --git a/action.yml b/action.yml index 6712b4e..f802c94 100644 --- a/action.yml +++ b/action.yml @@ -15,15 +15,13 @@ inputs: default: 'false' required: false tag-edge: - description: 'Branch that will be tagged as edge (default ${{ repo.default_branch }})' + description: 'Branch that will be tagged as edge (default repo.default_branch)' required: false sep-tags: description: 'Separator to use for tags output (default \n)' - default: '\n' required: false sep-labels: description: 'Separator to use for labels output (default \n)' - default: '\n' required: false github-token: description: 'GitHub Token as provided by secrets' diff --git a/dist/index.js b/dist/index.js index e9945f1..44ff56a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -115,7 +115,6 @@ function run() { const context = github.context(); const repo = yield github.repo(inputs.githubToken); core.startGroup(`Context info`); - core.info(`repo: ${context.repo}`); core.info(`eventName: ${context.eventName}`); core.info(`sha: ${context.sha}`); core.info(`ref: ${context.ref}`); @@ -133,12 +132,16 @@ function run() { core.setOutput('version', version); const tags = meta.tags(); core.startGroup(`Docker tags`); - core.info(JSON.stringify(tags)); + for (let tag of tags) { + core.info(tag); + } core.endGroup(); core.setOutput('tags', tags.join(inputs.sepTags)); const labels = meta.labels(); core.startGroup(`Docker labels`); - core.info(JSON.stringify(labels)); + for (let label of labels) { + core.info(label); + } core.endGroup(); core.setOutput('labels', labels.join(inputs.sepTags)); } diff --git a/src/main.ts b/src/main.ts index ff73bcf..052f891 100644 --- a/src/main.ts +++ b/src/main.ts @@ -15,7 +15,6 @@ async function run() { const context: Context = github.context(); const repo: ReposGetResponseData = await github.repo(inputs.githubToken); core.startGroup(`Context info`); - core.info(`repo: ${context.repo}`); core.info(`eventName: ${context.eventName}`); core.info(`sha: ${context.sha}`); core.info(`ref: ${context.ref}`); @@ -36,13 +35,17 @@ async function run() { const tags: Array = meta.tags(); core.startGroup(`Docker tags`); - core.info(JSON.stringify(tags)); + for (let tag of tags) { + core.info(tag); + } core.endGroup(); core.setOutput('tags', tags.join(inputs.sepTags)); const labels: Array = meta.labels(); core.startGroup(`Docker labels`); - core.info(JSON.stringify(labels)); + for (let label of labels) { + core.info(label); + } core.endGroup(); core.setOutput('labels', labels.join(inputs.sepTags)); } catch (error) {