From 1583932470799b99f25e1a1e7e643b444e15d33d Mon Sep 17 00:00:00 2001 From: Gijsdeman Date: Thu, 14 Nov 2024 00:14:30 +0100 Subject: [PATCH 1/4] feat(publish): add publishing options --- .github/workflows/docker-release.yml | 111 +++++++++++++++++++++++++ .github/workflows/npm-release.yml | 74 +++++++++++++++++ .github/workflows/semantic-release.yml | 85 ------------------- .github/workflows/versioning.yml | 7 ++ 4 files changed, 192 insertions(+), 85 deletions(-) create mode 100644 .github/workflows/docker-release.yml create mode 100644 .github/workflows/npm-release.yml delete mode 100644 .github/workflows/semantic-release.yml diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml new file mode 100644 index 0000000..9f6bacc --- /dev/null +++ b/.github/workflows/docker-release.yml @@ -0,0 +1,111 @@ +name: Semantic Release + +on: + workflow_call: + inputs: + projects: + required: true + description: 'Comma-separated list of projects to release' + type: string + version: + required: true + description: 'Version of the Docker release' + type: string + docker_registry: + required: true + type: string + github_registry: + required: false + type: string + env_file: + required: false + description: 'Contents of the ENV file to use during building, should only be used as an exception.' + type: string + docker_paths: + required: true + description: 'Comma-separated list of Docker paths corresponding to each project' + type: string + secrets: + REGISTRY_USERNAME: + required: true + REGISTRY_PASSWORD: + required: true + +jobs: + release: + runs-on: ubuntu-latest + if: ${{ inputs.version != '' }} + permissions: + packages: write + container: + image: docker:dind + strategy: + matrix: + project: ${{ fromJson(inputs.projects) }} + docker_path: ${{ fromJson(inputs.docker_paths) }} + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up environment + if: ${{ inputs.env_file != '' }} + env: + ENV_FILE: ${{ inputs.env_file }} + run: | + echo '${ENV_FILE}' > ${{ matrix.project }}/.env + + - name: Extract Image Name + id: extract + run: | + input="${{ matrix.docker_path }}" + result="${input#*/}" + echo "::set-output name=part::$result" + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Container (GitHub) + if: ${{ inputs.github_registry == 'true' }} + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and Push Docker Image (GitHub) + if: ${{ inputs.github_registry == 'true' }} + uses: docker/build-push-action@v6 + with: + context: . + platforms: linux/amd64 + push: true + tags: | + ghcr.io/gewis/${{ steps.extract.outputs.part }}:latest + ghcr.io/gewis/${{ steps.extract.outputs.part }}:${{inputs.version}} + cache-from: type=gha + cache-to: type=gha,mode=max + file: ${{ matrix.project }}/Dockerfile + + - name: Login to Container (Registry) + uses: docker/login-action@v3 + with: + registry: ${{ inputs.docker_registry }} + username: ${{ secrets.REGISTRY_USERNAME }} + password: ${{ secrets.REGISTRY_PASSWORD }} + + - name: Build and Push Docker Image (Registry) + uses: docker/build-push-action@v6 + with: + context: . + platforms: linux/amd64 + push: true + tags: | + ${{ inputs.docker_registry }}/${{ matrix.docker_path }}:latest + ${{ inputs.docker_registry }}/${{ matrix.docker_path }}:${{ inputs.version }} + cache-from: type=gha + cache-to: type=gha,mode=max + file: ${{ matrix.project }}/Dockerfile diff --git a/.github/workflows/npm-release.yml b/.github/workflows/npm-release.yml new file mode 100644 index 0000000..3353288 --- /dev/null +++ b/.github/workflows/npm-release.yml @@ -0,0 +1,74 @@ +name: Semantic Release + +on: + workflow_call: + inputs: + node-version: + required: false + type: string + description: 'The node version required for the project.' + default: '20.x' + # options: + # - 22.x + # - 20.x + # - 18.x + version: + required: true + description: 'Version of the package(s)' + type: string + lerna: + required: false + description: 'Whether project is a lerna project' + type: string + +jobs: + publish-npm: + runs-on: ubuntu-latest + if: ${{ inputs.lerna != 'true' && inputs.version != '' }} + permissions: + contents: read + packages: write + attestations: write + id-token: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: '20.x' + registry-url: 'https://npm.pkg.github.com' + scope: '@gewis' + + - run: npm publish --access public + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + publish-npm-lerna: + runs-on: ubuntu-latest + if: ${{ inputs.lerna == 'true' && inputs.version != '' }} + permissions: + packages: write + contents: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Git Config + run: git config user.email 'github-actions@github.com' && git config user.name 'github-actions' + + - uses: actions/setup-node@v4 + with: + node-version: '20.x' + registry-url: 'https://npm.pkg.github.com' + scope: '@gewis' + + - name: Lerna Publish + run: npx --yes lerna version ${{ inputs.version }} --amend --yes && npx lerna publish from-git --yes + env: + NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Push Tags + run: git push --force-with-lease --follow-tags diff --git a/.github/workflows/semantic-release.yml b/.github/workflows/semantic-release.yml deleted file mode 100644 index c1fd9b8..0000000 --- a/.github/workflows/semantic-release.yml +++ /dev/null @@ -1,85 +0,0 @@ -name: Semantic Release - -on: - workflow_call: - inputs: - projects: - required: true - description: "Comma-separated list of projects to release" - type: string - docker_registry: - required: true - type: string - env_file: - required: false - description: "Contents of the ENV file to use during building, should only be used as an exception." - type: string - docker_paths: - required: true - description: "Comma-separated list of Docker paths corresponding to each project" - type: string - secrets: - REGISTRY_USERNAME: - required: true - REGISTRY_PASSWORD: - required: true - -jobs: - versioning: - uses: ./.github/workflows/versioning.yml - - release: - runs-on: ubuntu-latest - needs: versioning - if: ${{ needs.versioning.outputs.next_version != '' }} - container: - image: docker:dind - strategy: - matrix: - project: ${{ fromJson(inputs.projects) }} - docker_path: ${{ fromJson(inputs.docker_paths) }} - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up environment - if: ${{ inputs.env_file != '' }} - env: - ENV_FILE: ${{ inputs.env_file }} - run: | - echo "${ENV_FILE}" > ${{ matrix.project }}/.env - - - name: Get Docker meta (for tags) - id: meta - uses: docker/metadata-action@v5 - with: - images: | - ${{ inputs.docker_registry }}/${{ matrix.docker_path }} - tags: | - ${{ needs.versioning.outputs.next_version }} - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to Container Registry - uses: docker/login-action@v3 - with: - registry: ${{ inputs.docker_registry }} - username: ${{ secrets.REGISTRY_USERNAME }} - password: ${{ secrets.REGISTRY_PASSWORD }} - - - name: Build and push Docker image - uses: docker/build-push-action@v6 - with: - context: . - platforms: linux/amd64 - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=gha - cache-to: type=gha,mode=max - file: ${{ matrix.project }}/Dockerfile diff --git a/.github/workflows/versioning.yml b/.github/workflows/versioning.yml index c12cc2e..8bb9648 100644 --- a/.github/workflows/versioning.yml +++ b/.github/workflows/versioning.yml @@ -2,6 +2,11 @@ name: Versioning on: workflow_call: + inputs: + dry-run: + required: false + description: "Whether to perform versioning without making a release" + type: string outputs: next_version: description: "Next version for tagging and releasing" @@ -23,5 +28,7 @@ jobs: - name: Semantic Release uses: cycjimmy/semantic-release-action@v4 id: semantic + with: + dry_run: ${{ inputs.dry-run }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 9df52a11094db3c06cee053aac4875ee40685fcf Mon Sep 17 00:00:00 2001 From: Samuel Date: Fri, 15 Nov 2024 21:33:11 +0100 Subject: [PATCH 2/4] feat!: split lint and build action by package manager BREAKING CHANGE: modifies the name of the typescript flows --- .../{typescript-lint-and-build.yml => lint-and-build-yarn.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{typescript-lint-and-build.yml => lint-and-build-yarn.yml} (100%) diff --git a/.github/workflows/typescript-lint-and-build.yml b/.github/workflows/lint-and-build-yarn.yml similarity index 100% rename from .github/workflows/typescript-lint-and-build.yml rename to .github/workflows/lint-and-build-yarn.yml From 9b8abc76697e6704e5d3333c9f1c061e5ba78acb Mon Sep 17 00:00:00 2001 From: Gijsdeman Date: Fri, 15 Nov 2024 21:55:43 +0100 Subject: [PATCH 3/4] chore: make workflows consistent --- .github/workflows/docker-build.yml | 4 +- .github/workflows/docker-release.yml | 40 +++++----- .github/workflows/lint-and-build-npm.yml | 96 +++++++++++++++++++++++ .github/workflows/lint-and-build-yarn.yml | 92 +++------------------- .github/workflows/npm-release.yml | 21 +++-- .github/workflows/validate-workflows.yml | 4 +- .github/workflows/versioning.yml | 10 +-- 7 files changed, 149 insertions(+), 118 deletions(-) create mode 100644 .github/workflows/lint-and-build-npm.yml diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 584a9a5..9c67c61 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -5,7 +5,7 @@ on: inputs: projects: required: true - description: "Comma-separated list of projects to build" + description: 'Comma-separated list of projects to build' type: string jobs: @@ -35,4 +35,4 @@ jobs: push: false cache-from: type=gha cache-to: type=gha,mode=max - file: ${{ matrix.project }}/Dockerfile \ No newline at end of file + file: ${{ matrix.project }}/Dockerfile diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml index 9f6bacc..f807cb7 100644 --- a/.github/workflows/docker-release.yml +++ b/.github/workflows/docker-release.yml @@ -1,4 +1,4 @@ -name: Semantic Release +name: Docker Release on: workflow_call: @@ -11,17 +11,19 @@ on: required: true description: 'Version of the Docker release' type: string - docker_registry: + docker-registry: required: true + description: 'Docker registry to push the Docker image to' type: string - github_registry: + github-registry: required: false + description: 'Whether to push the image to the GitHub registry' type: string - env_file: + env-file: required: false description: 'Contents of the ENV file to use during building, should only be used as an exception.' type: string - docker_paths: + docker-paths: required: true description: 'Comma-separated list of Docker paths corresponding to each project' type: string @@ -42,25 +44,25 @@ jobs: strategy: matrix: project: ${{ fromJson(inputs.projects) }} - docker_path: ${{ fromJson(inputs.docker_paths) }} + docker-path: ${{ fromJson(inputs.docker-paths) }} steps: - name: Checkout repository uses: actions/checkout@v4 - name: Set up environment - if: ${{ inputs.env_file != '' }} + if: ${{ inputs.env-file != '' }} env: - ENV_FILE: ${{ inputs.env_file }} + ENV_FILE: ${{ inputs.env-file }} run: | - echo '${ENV_FILE}' > ${{ matrix.project }}/.env + echo "${ENV_FILE}" > ${{ matrix.project }}/.env - name: Extract Image Name id: extract run: | - input="${{ matrix.docker_path }}" + input="${{ matrix.docker-path }}" result="${input#*/}" - echo "::set-output name=part::$result" + echo "{name}={part}" >> $result - name: Set up QEMU uses: docker/setup-qemu-action@v3 @@ -68,8 +70,8 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 - - name: Login to Container (GitHub) - if: ${{ inputs.github_registry == 'true' }} + - name: Login to Registry (GitHub) + if: ${{ inputs.github-registry == 'true' }} uses: docker/login-action@v3 with: registry: ghcr.io @@ -77,7 +79,7 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Build and Push Docker Image (GitHub) - if: ${{ inputs.github_registry == 'true' }} + if: ${{ inputs.github-registry == 'true' }} uses: docker/build-push-action@v6 with: context: . @@ -90,22 +92,22 @@ jobs: cache-to: type=gha,mode=max file: ${{ matrix.project }}/Dockerfile - - name: Login to Container (Registry) + - name: Login to Registry (Custom) uses: docker/login-action@v3 with: - registry: ${{ inputs.docker_registry }} + registry: ${{ inputs.docker-registry }} username: ${{ secrets.REGISTRY_USERNAME }} password: ${{ secrets.REGISTRY_PASSWORD }} - - name: Build and Push Docker Image (Registry) + - name: Build and Push Docker Image (Custom) uses: docker/build-push-action@v6 with: context: . platforms: linux/amd64 push: true tags: | - ${{ inputs.docker_registry }}/${{ matrix.docker_path }}:latest - ${{ inputs.docker_registry }}/${{ matrix.docker_path }}:${{ inputs.version }} + ${{ inputs.docker-registry }}/${{ matrix.docker-path }}:latest + ${{ inputs.docker-registry }}/${{ matrix.docker-path }}:${{ inputs.version }} cache-from: type=gha cache-to: type=gha,mode=max file: ${{ matrix.project }}/Dockerfile diff --git a/.github/workflows/lint-and-build-npm.yml b/.github/workflows/lint-and-build-npm.yml new file mode 100644 index 0000000..edc92c9 --- /dev/null +++ b/.github/workflows/lint-and-build-npm.yml @@ -0,0 +1,96 @@ +name: TypeScript Lint and Build with NPM + +on: + workflow_call: + inputs: + working-directory: + required: false + type: string + default: '.' + node-version: + required: false + type: string + default: '20.x' + artifact-name: + required: false + type: string + description: 'Name of artifact to use' + artifact-path: + required: false + type: string + description: 'Path to place artifact' + prepare-command: + required: false + type: string + description: 'Command to run directly after checkout.' + cleanup-command: + required: false + type: string + description: 'Command to run after the workflow (even if failed).' + lint: + type: boolean + description: 'Run the lint step.' + default: true + format: + type: boolean + description: 'Run the format step.' + default: false + test: + type: boolean + description: 'Run the test step.' + default: false + build: + type: boolean + description: 'Run the build step.' + default: true + +jobs: + npm-steps: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Artifact + uses: actions/download-artifact@v4 + with: + name: ${{ inputs.artifact-name }} + path: ${{ inputs.artifact-path }} + if: ${{ inputs.artifact-name != '' }} + + - name: Prepare + run: ${{ inputs.prepare-command }} + if: ${{ inputs.prepare-command != '' }} + + - name: Set Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ inputs.node-version }} + + - name: Install dependencies + working-directory: ${{ inputs.working-directory }} + run: npm install + + - name: Lint the project + working-directory: ${{ inputs.working-directory }} + run: npm run lint + if: ${{ inputs.lint }} + + - name: Format the project + working-directory: ${{ inputs.working-directory }} + run: npm run format + if: ${{ inputs.format }} + + - name: Test the project + working-directory: ${{ inputs.working-directory }} + run: npm run test + if: ${{ inputs.test }} + + - name: Build the project + working-directory: ${{ inputs.working-directory }} + run: npm run build + if: ${{ inputs.build }} + + - name: Cleanup + run: ${{ inputs.cleanup-command }} + if: ${{ inputs.cleanup-command != '' && always() }} diff --git a/.github/workflows/lint-and-build-yarn.yml b/.github/workflows/lint-and-build-yarn.yml index f5f5306..9fac0e5 100644 --- a/.github/workflows/lint-and-build-yarn.yml +++ b/.github/workflows/lint-and-build-yarn.yml @@ -1,66 +1,51 @@ -name: Build and Lint TypeScript Project +name: TypeScript Lint and Build with Yarn on: workflow_call: inputs: working-directory: required: false - description: "The directory where the TypeScript project is located." type: string - default: "." + default: '.' node-version: required: false type: string - description: "The node version required for the TypeScript project." - default: "20.x" - # options: - # - 22.x - # - 20.x - # - 18.x - package-manager: - required: false - type: string - description: "The package manager to use for the TypeScript project." - default: "npm" - # options: - # - yarn - # - npm + default: '20.x' artifact-name: required: false type: string - description: "Name of artifact to use" + description: 'Name of artifact to use' artifact-path: required: false type: string - description: "Path to place artifact" + description: 'Path to place artifact' prepare-command: required: false type: string - description: "Command to run directly after checkout." + description: 'Command to run directly after checkout.' cleanup-command: required: false type: string - description: "Command to run after the workflow (even if failed)." + description: 'Command to run after the workflow (even if failed).' lint: type: boolean - description: "Use the lint step." + description: 'Run the lint step.' default: true format: type: boolean - description: "Use the format step." + description: 'Run the format step.' default: false test: type: boolean - description: "Use the test step." + description: 'Run the test step.' default: false build: type: boolean - description: "Use the build step." + description: 'Run the build step.' default: true jobs: - build-and-lint-yarn: - if: ${{ inputs.package-manager == 'yarn' }} + yarn-steps: runs-on: ubuntu-latest steps: - name: Checkout code @@ -116,57 +101,6 @@ jobs: dir: ${{ inputs.working-directory }} if: ${{ inputs.build }} - - name: Cleanup - run: ${{ inputs.cleanup-command }} - if: ${{ inputs.cleanup-command != '' && always() }} - - build-and-lint-npm: - if: ${{ inputs.package-manager == 'npm' }} - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Artifact - uses: actions/download-artifact@v4 - with: - name: ${{ inputs.artifact-name }} - path: ${{ inputs.artifact-path }} - if: ${{ inputs.artifact-name != '' }} - - - name: Prepare - run: ${{ inputs.prepare-command }} - if: ${{ inputs.prepare-command != '' }} - - - name: Set Node.js - uses: actions/setup-node@v4 - with: - node-version: ${{ inputs.node-version }} - - - name: Install dependencies - working-directory: ${{ inputs.working-directory }} - run: npm install - - - name: Lint the project - working-directory: ${{ inputs.working-directory }} - run: npm run lint - if: ${{ inputs.lint }} - - - name: Format the project - working-directory: ${{ inputs.working-directory }} - run: npm run format - if: ${{ inputs.format }} - - - name: Test the project - working-directory: ${{ inputs.working-directory }} - run: npm run test - if: ${{ inputs.test }} - - - name: Build the project - working-directory: ${{ inputs.working-directory }} - run: npm run build - if: ${{ inputs.build }} - - - name: Cleanup + - name: Cleanup run: ${{ inputs.cleanup-command }} if: ${{ inputs.cleanup-command != '' && always() }} diff --git a/.github/workflows/npm-release.yml b/.github/workflows/npm-release.yml index 3353288..3396bc5 100644 --- a/.github/workflows/npm-release.yml +++ b/.github/workflows/npm-release.yml @@ -1,4 +1,4 @@ -name: Semantic Release +name: NPM Release on: workflow_call: @@ -6,12 +6,8 @@ on: node-version: required: false type: string - description: 'The node version required for the project.' + description: 'The node version required for the project' default: '20.x' - # options: - # - 22.x - # - 20.x - # - 18.x version: required: true description: 'Version of the package(s)' @@ -34,13 +30,15 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - uses: actions/setup-node@v4 + - name: Setup Node + uses: actions/setup-node@v4 with: - node-version: '20.x' + node-version: ${{ inputs.node-version }} registry-url: 'https://npm.pkg.github.com' scope: '@gewis' - - run: npm publish --access public + - name: Publish + run: npm publish --access public env: NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -59,9 +57,10 @@ jobs: - name: Git Config run: git config user.email 'github-actions@github.com' && git config user.name 'github-actions' - - uses: actions/setup-node@v4 + - name: Setup Node + uses: actions/setup-node@v4 with: - node-version: '20.x' + node-version: ${{ inputs.node-version }} registry-url: 'https://npm.pkg.github.com' scope: '@gewis' diff --git a/.github/workflows/validate-workflows.yml b/.github/workflows/validate-workflows.yml index 77104cd..7dce858 100644 --- a/.github/workflows/validate-workflows.yml +++ b/.github/workflows/validate-workflows.yml @@ -1,9 +1,9 @@ -name: "Validate Workflow Files" +name: 'Validate Workflow Files' on: push: paths: - - ".github/workflows/*.yml" + - '.github/workflows/*.yml' jobs: validate-workflows: diff --git a/.github/workflows/versioning.yml b/.github/workflows/versioning.yml index 8bb9648..7bdb6fe 100644 --- a/.github/workflows/versioning.yml +++ b/.github/workflows/versioning.yml @@ -5,12 +5,12 @@ on: inputs: dry-run: required: false - description: "Whether to perform versioning without making a release" + description: 'Whether to perform versioning without making a release' type: string outputs: - next_version: - description: "Next version for tagging and releasing" - value: ${{ jobs.versioning.outputs.next_version }} + next-version: + description: 'Next version for tagging and releasing' + value: ${{ jobs.versioning.outputs.next-version }} jobs: versioning: @@ -20,7 +20,7 @@ jobs: pull-requests: write issues: write outputs: - next_version: ${{ steps.semantic.outputs.new_release_version }} + next-version: ${{ steps.semantic.outputs.new_release_version }} steps: - name: Checkout repository uses: actions/checkout@v4 From 03309e05dd63df1bdd2d26c1cd6d7fa5c252bca1 Mon Sep 17 00:00:00 2001 From: Gijsdeman Date: Fri, 15 Nov 2024 22:26:20 +0100 Subject: [PATCH 4/4] docs: update readme and add examples --- README.md | 170 ++++++++++++++++-------------- examples/docker-build.yml | 15 +++ examples/lint-and-build.yml | 19 ++++ examples/npm-semantic-release.yml | 25 +++++ examples/semantic-release.yml | 18 ++++ 5 files changed, 169 insertions(+), 78 deletions(-) create mode 100644 examples/docker-build.yml create mode 100644 examples/lint-and-build.yml create mode 100644 examples/npm-semantic-release.yml create mode 100644 examples/semantic-release.yml diff --git a/README.md b/README.md index cf230c2..c2dee76 100644 --- a/README.md +++ b/README.md @@ -5,120 +5,134 @@ Common and Reusable GitHub Actions for the GEWIS organization. -## Docker build -Workflow for building a docker image. +> [!NOTE] +> All inputs for the workflows should be provided as strings. However, sometimes a certain structure is expected. These are noted in the "Options" columns. + +## Lint and build +Workflow for linting, formatting, testing and building projects. Can be used for both `npm` and `yarn`. -### Example ```yaml -name: Docker Build +jobs: + build-and-lint-yarn: + uses: GEWIS/actions/.github/workflows/lint-and-build-npm.yml@v1.0.0 + with: + node-version: '22.x' + format: true + + build-and-lint-npm: + uses: GEWIS/actions/.github/workflows/lint-and-build-yarn.yml@v1.0.0 + with: + node-version: '20.x' + test: true +``` + +### Inputs + +| Input name | Description | Required | Options | Default value | +|-------------------|--------------------------------------------------------------|----------|------------------------|---------------| +| working-directory | The directory where the project is located. | ☐ | | `.` | +| node-version | The version of Node.js to use. | ☐ | `18.x`, `20.x`, `22.x` | `20.x` | +| artifact-name | The name of the artifact to use. | ☐ | | | +| artifact-path | The path where the artifact should be stored. | ☐ | | | +| prepare-command | The command to run before building (and and after checkout). | ☐ | | | +| cleanup-command | The command to run after building. | ☐ | | | +| lint | Whether to lint the project. | ☐ | `true`, `false` | `true` | +| format | Whether to format the project. | ☐ | `true`, `false` | `false` | +| test | Whether to run tests. | ☐ | `true`, `false` | `false` | +| build | Whether to build the project. | ☐ | `true`, `false` | `true` | -on: - push: - branches: - - main - pull_request: - branches: - - main +## Docker build +Workflow for building a docker image. Useful for, for example, testing if a container build succeeds on a develop branch. +```yaml jobs: dockerize: - uses: GEWIS/actions/.github/workflows/docker-build.yml@v0.0.2 + uses: GEWIS/actions/.github/workflows/docker-build.yml@v1.0.0 with: projects: '["."]' ``` - -## Semantic release -Workflow for building Docker images and releasing them. Includes versioning using `semantic-release-action`. - ### Inputs -| Input name | Description | Required | Types/values | Default value | -|-----------------|----------------------------------------------------------|----------|--------------|---------------| -| projects | A comma-separated list of projects to release. | ☑ | `string` | N/A | -| docker-registry | The docker registry to push the build image to. | ☑ | `string` | N/A | -| docker-paths | The docker namespace, project and image name to push to. | ☑ | `string` | N/A | -| env_file | Contents of the environment file to use during building. | ☐ | `string` | N/A | +| Input name | Description | Required | Options | Default value | +|------------|----------------------------------------------|----------|---------|---------------| +| projects | Comma-separated list of projects to release. | ☑ | | | -### Secrets -| Secret name | Secret value | -|-------------------|--------------------------------------------| -| REGISTRY_USERNAME | The username used to push to the registry. | -| REGISTRY_PASSWORD | The password used to push to the registry. | -### Example +## Docker release +Workflow for building Docker images and releasing them. Can be used to push to GitHub and any other registry. ```yaml -name: Semantic release - -on: - pull_request: - branches: - - main - jobs: build-and-lint: - uses: GEWIS/actions/.github/workflows/semantic-release.yml@v0.0.2 + uses: GEWIS/actions/.github/workflows/docker-release.yml@v1.0.0 with: projects: '["."]' - docker_registry: 'abc.docker-registry.gewis.nl' - docker_tag: 'nc/aurora/core' + docker-registry: 'abc.docker-registry.gewis.nl' + docker-path: 'nc/aurora/core' + version: '4.0.40' + github-registry: 'true' ``` -## Lint and build -Workflow for linting, formatting, testing and building Typescript projects. - ### Inputs -| Input name | Description | Required | Types/values | Default value | -|-------------------|--------------------------------------------------------------|----------|------------------------|---------------| -| working-directory | The directory where the TypeScript project is located. | ☐ | `string` | `.` | -| node-version | The version of Node.js to use. | ☐ | `18.x`, `20.x`, `22.x` | `20.x` | -| package-manager | The package manager to use. | ☐ | `npm`, `yarn` | `npm` | -| artifact-name | The name of the artifact to use. | ☐ | `string` | N/A | -| artifact-path | The path where the artifact should be stored. | ☐ | `string` | N/A | -| prepare-command | The command to run before building (and and after checkout). | ☐ | `string` | N/A | -| cleanup-command | The command to run after building. | ☐ | `string` | N/A | -| lint | Whether to lint the project. | ☐ | `boolean` | `true` | -| format | Whether to format the project. | ☐ | `boolean` | `false` | -| test | Whether to run tests. | ☐ | `boolean` | `false` | -| build | Whether to build the project. | ☐ | `boolean` | `true` | - -### Example +| Input name | Description | Required | Options | Default value | +|-----------------|----------------------------------------------------------|----------|-----------------|---------------| +| projects | Comma-separated list of projects to release. | ☑ | | | +| version | Version of the Docker release. | ☑ | | | +| docker-registry | The docker registry to push the build image to. | ☑ | | | +| github-registry | Whether to push the image to the GitHub registry. | ☐ | `true`, `false` | `false` | +| env-file | Contents of the environment file to use during building. | ☐ | | | +| docker-paths | The docker namespace, project and image name to push to. | ☑ | | | -```yaml -name: Lint and build +### Secrets -on: - push: - branches: - - develop - pull_request: - branches: - - develop +| Secret name | Secret value | +|--------------------|---------------------------------------------------| +| REGISTRY\_USERNAME | The username used to push to the custom registry. | +| REGISTRY\_PASSWORD | The password used to push to the custom registry. | +## NPM release +Workflow for releasing a NPM package on GitHub. + +```yaml jobs: build-and-lint: - uses: GEWIS/actions/.github/workflows/typescript-lint-and-build.yml@v0.0.2 + uses: GEWIS/actions/.github/workflows/npm-release.yml@v1.0.0 with: - node-version: '22.x' - package-manager: 'yarn' - format: true + version: '4.0.40' + lerna: 'true' ``` +### Inputs + +| Input name | Description | Required | Options | Default value | +|--------------|-----------------------------------------|----------|------------------------|---------------| +| node-version | The version of Node.js to use. | ☐ | `18.x`, `20.x`, `22.x` | `20.x` | +| version | Version of the NPM release. | ☑ | | | +| lerna | Whether the project is a lerna project. | ☐ | `true`, `false` | `false` | + + ## Versioning Workflow for versioning a project using `semantic-release-action`. -### Example ```yaml -name: Versioning - -on: - pull_request: - branches: - - main - jobs: build-and-lint: - uses: GEWIS/actions/.github/workflows/versioning.yml@v0.0.2 + uses: GEWIS/actions/.github/workflows/versioning.yml@v1.0.0 ``` +### Inputs + +| Input name | Description | Required | Options | Default value | +|------------|------------------------------------------------------|----------|----------|---------------| +| dry-run | Whether to run a dry run of the semantic versioning. | ☐ | `string` | `.` | + +### Outputs + +| Output name | Description | Options | Default value | +|--------------|-------------------------------------------|----------|---------------| +| next-version | The next semantic version of the project. | `string` | "" | + +## Examples + +Example workflows for building, versioning and releasing a project can be found in the [examples](./examples) directory. \ No newline at end of file diff --git a/examples/docker-build.yml b/examples/docker-build.yml new file mode 100644 index 0000000..e905984 --- /dev/null +++ b/examples/docker-build.yml @@ -0,0 +1,15 @@ +name: Docker Build + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + dockerize: + uses: GEWIS/actions/.github/workflows/docker-build.yml@1.0.0 + with: + projects: '["."]' \ No newline at end of file diff --git a/examples/lint-and-build.yml b/examples/lint-and-build.yml new file mode 100644 index 0000000..a1004cf --- /dev/null +++ b/examples/lint-and-build.yml @@ -0,0 +1,19 @@ +name: Lint and build + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build-and-lint: + uses: GEWIS/actions/.github/workflows/typescript-lint-and-build.yml@1.0.0 + with: + node-version: "22.x" + package-manager: "yarn" + lint: true + format: true + build: true \ No newline at end of file diff --git a/examples/npm-semantic-release.yml b/examples/npm-semantic-release.yml new file mode 100644 index 0000000..9fc55aa --- /dev/null +++ b/examples/npm-semantic-release.yml @@ -0,0 +1,25 @@ +name: Publish + +on: + workflow_dispatch: + push: + branches: + - 'main' + pull_request: + branches: + - 'main' + +jobs: + versioning: + uses: GEWIS/actions/.github/workflows/npm-release.yml@1.0.0 + with: + dry-run: 'true', + + publish-npm: + uses: GEWIS/actions/.github/workflows/npm-release.yml@1.0.0 + needs: versioning + if: ${{ needs.versioning.outputs.next_version != '' }} + with: + node-version: '22.x' + version: ${{ needs.versioning.outputs.next_version }} + lerna: 'true' \ No newline at end of file diff --git a/examples/semantic-release.yml b/examples/semantic-release.yml new file mode 100644 index 0000000..0cdd75c --- /dev/null +++ b/examples/semantic-release.yml @@ -0,0 +1,18 @@ +name: Semantic release + +on: + push: + branches: + - main + +jobs: + semantic-release: + uses: GEWIS/actions/.github/workflows/semantic-release.yml@1.0.0 + with: + projects: "['.']" + docker_registry: "abc.docker-registry.gewis.nl" + docker_paths: "['eou/plankapi']" + github-registry: "true" + secrets: + REGISTRY_USERNAME: ${{ secrets.SVC_GH_ABCEOU_USERNAME }} + REGISTRY_PASSWORD: ${{ secrets.SVC_GH_ABCEOU_PWD }} \ No newline at end of file