Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Initial commit #4

Merged
merged 113 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
333b7e2
Initial commit
ljtill Jun 22, 2024
533548d
Initial commit
ljtill Jun 22, 2024
43434fe
Initial commit
ljtill Jun 22, 2024
ecfbb52
Initial commit
ljtill Jun 22, 2024
6b17009
Initial commit
ljtill Jun 22, 2024
6328fc0
Initial commit
ljtill Jun 22, 2024
8374d24
Initial commit
ljtill Jun 22, 2024
1481ea6
Initial commit
ljtill Jun 22, 2024
ab72cb9
Initial commit
ljtill Jun 22, 2024
4de2173
Initial commit
ljtill Jun 22, 2024
8ec710b
Initial commit
ljtill Jun 22, 2024
dcc1bbb
Initial commit
ljtill Jun 22, 2024
b51eddb
Initial commit
ljtill Jun 22, 2024
12a1936
Initial commit
ljtill Jun 22, 2024
76a89cc
Initial commit
ljtill Jun 22, 2024
2651a5b
Initial commit
ljtill Jun 24, 2024
3b370ea
Initial commit
ljtill Jun 24, 2024
82dd417
Initial commit
ljtill Jun 24, 2024
6858c7f
Initial commit
ljtill Jun 24, 2024
54ca0ae
Initial commit
ljtill Jun 24, 2024
986d835
Initial commit
ljtill Jun 24, 2024
8b36266
Initial commit
ljtill Jun 24, 2024
aef821c
Initial commit
ljtill Jun 24, 2024
b006b8e
Initial commit
ljtill Jun 24, 2024
2507eef
Initial commit
ljtill Jun 24, 2024
2c81e22
Initial commit
ljtill Jun 24, 2024
bae72ea
Initial commit
ljtill Jun 24, 2024
f538bc4
Initial commit
ljtill Jun 24, 2024
227522c
Initial commit
ljtill Jun 24, 2024
e063aad
Initial commit
ljtill Jun 24, 2024
7950cce
Initial commit
ljtill Jun 24, 2024
105724a
Initial commit
ljtill Jun 24, 2024
19005e2
Initial commit
ljtill Jun 24, 2024
645b405
Initial commit
ljtill Jun 24, 2024
b8f56b6
Initial commit
ljtill Jun 24, 2024
73f2495
Initial commit
ljtill Jun 24, 2024
d5cd42e
Initial commit
ljtill Jun 24, 2024
71de5e2
Initial commit
ljtill Jun 24, 2024
1dc5b49
Initial commit
ljtill Jun 24, 2024
05a98c6
Initial commit
ljtill Jun 24, 2024
01aebf0
Initial commit
ljtill Jun 24, 2024
9aed39a
Initial commit
ljtill Jun 24, 2024
2344ff9
Initial commit
ljtill Jun 24, 2024
4139acb
Initial commit
ljtill Jun 24, 2024
0a2befa
Initial commit
ljtill Jun 24, 2024
b800886
Initial commit
ljtill Jun 24, 2024
1b81e62
Initial commit
ljtill Jun 24, 2024
a06a5ee
Initial commit
ljtill Jun 24, 2024
06a28e1
Initial commit
ljtill Jun 24, 2024
913146e
Initial commit
ljtill Jun 24, 2024
4ae2c34
Initial commit
ljtill Jun 24, 2024
fb889ea
Initial commit
ljtill Jun 24, 2024
95d210c
Initial commit
ljtill Jun 24, 2024
4edfc33
Initial commit
ljtill Jun 24, 2024
21bcf77
Initial commit
ljtill Jun 24, 2024
3eff677
Initial commit
ljtill Jun 24, 2024
e69f878
Initial commit
ljtill Jun 24, 2024
7de0b6c
Initial commit
ljtill Jun 24, 2024
ef1ce48
Initial commit
ljtill Jun 24, 2024
efc81a1
Initial commit
ljtill Jun 24, 2024
5ac5df7
Initial commit
ljtill Jun 25, 2024
92397f3
Initial commit
ljtill Jun 25, 2024
7083e4e
Initial commit
ljtill Jun 25, 2024
2898638
Initial commit
ljtill Jun 25, 2024
dd8394d
Initial commit
ljtill Jun 25, 2024
321de25
Initial commit
ljtill Jun 25, 2024
a7ce175
Initial commit
ljtill Jun 25, 2024
2fbef23
Initial commit
ljtill Jun 25, 2024
aa2b6ba
Initial commit
ljtill Jun 25, 2024
0024c8d
Initial commit
ljtill Jun 25, 2024
eae47d7
Initial commit
ljtill Jun 25, 2024
0b6055a
Initial commit
ljtill Jun 26, 2024
9f6a188
Initial commit
ljtill Jun 26, 2024
a55d077
Initial commit
ljtill Jun 26, 2024
b1ac9bd
Initial commit
ljtill Jun 26, 2024
6fa6610
Initial commit
ljtill Jun 27, 2024
6d26b5c
Initial commit
ljtill Jun 27, 2024
626ddaf
Initial commit
ljtill Jun 27, 2024
7fd72c0
Initial commit
ljtill Jun 27, 2024
efa7e88
Initial commit
ljtill Jun 27, 2024
66181d4
Initial commit
ljtill Jun 27, 2024
fe8bd7d
Initial commit
ljtill Jun 27, 2024
d358769
Initial commit
ljtill Jun 27, 2024
8610f2f
Initial commit
ljtill Jun 27, 2024
c969b2c
Initial commit
ljtill Jun 27, 2024
c18dac8
Initial commit
ljtill Jun 27, 2024
30b0676
Initial commit
ljtill Jun 27, 2024
d661cd6
Initial commit
ljtill Jun 27, 2024
7351b0b
Initial commit
ljtill Jun 27, 2024
f044282
Initial commit
ljtill Jun 27, 2024
d427601
Initial commit
ljtill Jun 27, 2024
0a6da69
Initial commit
ljtill Jun 27, 2024
241cd75
Initial commit
ljtill Jun 27, 2024
47d0bbb
Initial commit
ljtill Jun 27, 2024
8763e2b
Initial commit
ljtill Jun 27, 2024
1002a64
Initial commit
ljtill Jun 27, 2024
7c0b2c4
Initial commit
ljtill Jun 27, 2024
2dc3731
Initial commit
ljtill Jun 27, 2024
ef2bb23
Initial commit
ljtill Jun 27, 2024
b7fc4e5
Initial commit
ljtill Jun 27, 2024
75f56e5
Initial commit
ljtill Jun 27, 2024
05ad681
Initial commit
ljtill Jun 27, 2024
b662a18
Initial commit
ljtill Jun 27, 2024
e3f60d0
Initial commit
ljtill Jun 27, 2024
5b4faf9
Initial commit
ljtill Jun 27, 2024
fa229b8
Initial commit
ljtill Jun 27, 2024
2af9334
Initial commit
ljtill Jun 27, 2024
4e1fb90
Initial commit
ljtill Jun 27, 2024
aa2a78a
Initial commit
ljtill Jun 27, 2024
8eea55f
Initial commit
ljtill Jun 27, 2024
b585936
Initial commit
ljtill Jul 3, 2024
f1a08d4
Initial commit
ljtill Jul 3, 2024
efb6684
Initial commit
ljtill Jul 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/linters/.eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ rules:
'eslint-comments/no-use': 'off',
'eslint-comments/no-unused-disable': 'off',
'i18n-text/no-en': 'off',
'import/named': 'off',
'import/no-namespace': 'off',
'no-console': 'off',
'no-unused-vars': 'off',
Expand All @@ -55,7 +56,7 @@ rules:
['error', { 'allowExpressions': true }],
'@typescript-eslint/func-call-spacing': ['error', 'never'],
'@typescript-eslint/no-array-constructor': 'error',
'@typescript-eslint/no-empty-interface': 'error',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-explicit-any': 'error',
'@typescript-eslint/no-extraneous-class': 'error',
'@typescript-eslint/no-for-in-array': 'error',
Expand Down
299 changes: 88 additions & 211 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,229 +1,106 @@
# Create a GitHub Action Using TypeScript
# Azure Deployment Stacks Action

[![GitHub Super-Linter](https://github.com/actions/typescript-action/actions/workflows/linter.yml/badge.svg)](https://github.com/super-linter/super-linter)
![CI](https://github.com/actions/typescript-action/actions/workflows/ci.yml/badge.svg)
[![Check dist/](https://github.com/actions/typescript-action/actions/workflows/check-dist.yml/badge.svg)](https://github.com/actions/typescript-action/actions/workflows/check-dist.yml)
[![CodeQL](https://github.com/actions/typescript-action/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/actions/typescript-action/actions/workflows/codeql-analysis.yml)
[![Coverage](./badges/coverage.svg)](./badges/coverage.svg)

Use this template to bootstrap the creation of a TypeScript action. :rocket:

This template includes compilation support, tests, a validation workflow,
publishing, and versioning guidance.

If you are new, there's also a simpler introduction in the
[Hello world JavaScript action repository](https://github.com/actions/hello-world-javascript-action).

## Create Your Own Action

To create your own action, you can use this repository as a template! Just
follow the below instructions:

1. Click the **Use this template** button at the top of the repository
1. Select **Create a new repository**
1. Select an owner and name for your new repository
1. Click **Create repository**
1. Clone your new repository

> [!IMPORTANT]
>
> Make sure to remove or update the [`CODEOWNERS`](./CODEOWNERS) file! For
> details on how to use this file, see
> [About code owners](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners).

## Initial Setup

After you've cloned the repository to your local machine or codespace, you'll
need to perform some initial setup steps before you can develop your action.

> [!NOTE]
>
> You'll need to have a reasonably modern version of
> [Node.js](https://nodejs.org) handy (20.x or later should work!). If you are
> using a version manager like [`nodenv`](https://github.com/nodenv/nodenv) or
> [`nvm`](https://github.com/nvm-sh/nvm), this template has a `.node-version`
> file at the root of the repository that will be used to automatically switch
> to the correct version when you `cd` into the repository. Additionally, this
> `.node-version` file is used by GitHub Actions in any `actions/setup-node`
> actions.

1. :hammer_and_wrench: Install the dependencies

```bash
npm install
```

1. :building_construction: Package the TypeScript for distribution

```bash
npm run bundle
```

1. :white_check_mark: Run the tests

```bash
$ npm test

PASS ./index.test.js
✓ throws invalid number (3ms)
✓ wait 500 ms (504ms)
✓ test runs (95ms)

...
```

## Update the Action Metadata

The [`action.yml`](action.yml) file defines metadata about your action, such as
input(s) and output(s). For details about this file, see
[Metadata syntax for GitHub Actions](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions).
![Icon](./docs/static/stacks.jpg)

When you copy this repository, update `action.yml` with the name, description,
inputs, and outputs for your action.

## Update the Action Code

The [`src/`](./src/) directory is the heart of your action! This contains the
source code that will be run when your action is invoked. You can replace the
contents of this directory with your own code.

There are a few things to keep in mind when writing your action code:

- Most GitHub Actions toolkit and CI/CD operations are processed asynchronously.
In `main.ts`, you will see that the action is run in an `async` function.

```javascript
import * as core from '@actions/core'
//...

async function run() {
try {
//...
} catch (error) {
core.setFailed(error.message)
}
}
```

For more information about the GitHub Actions toolkit, see the
[documentation](https://github.com/actions/toolkit/blob/master/README.md).

So, what are you waiting for? Go ahead and start customizing your action!

1. Create a new branch

```bash
git checkout -b releases/v1
```

1. Replace the contents of `src/` with your action code
1. Add tests to `__tests__/` for your source code
1. Format, test, and build the action

```bash
npm run all
```

> This step is important! It will run [`ncc`](https://github.com/vercel/ncc)
> to build the final JavaScript action code with all dependencies included.
> If you do not run this step, your action will not work correctly when it is
> used in a workflow. This step also includes the `--license` option for
> `ncc`, which will create a license file for all of the production node
> modules used in your project.
[![GitHub Super-Linter](https://github.com/ljtill/azure-deployment-stacks-action/actions/workflows/linter.yml/badge.svg)](https://github.com/super-linter/super-linter)
![CI](https://github.com/ljtill/azure-deployment-stacks-action/actions/workflows/ci.yml/badge.svg)
[![Check dist/](https://github.com/ljtill/azure-deployment-stacks-action/actions/workflows/check-dist.yml/badge.svg)](https://github.com/ljtill/azure-deployment-stacks-action/actions/workflows/check-dist.yml)
[![CodeQL](https://github.com/ljtill/azure-deployment-stacks-action/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/ljtill/azure-deployment-stacks-action/actions/workflows/codeql-analysis.yml)
[![Coverage](./badges/coverage.svg)](./badges/coverage.svg)

1. Commit your changes
This repository contains a [GitHub Action](https://docs.github.com/actions) that
allows engineers to create, update, delete, and validate
[Azure Deployment Stacks](https://learn.microsoft.com/azure/azure-resource-manager/bicep/deployment-stacks)
directly from their GitHub workflows. It supports a variety of inputs for scopes
and options, making it flexible and easy to use for managing Azure resources.
Whether you need to define the scope at the management group, subscription, or
resource group level, this action provides the necessary parameters to tailor
deployments to your specific needs. Additionally, it includes options for
setting the location, mode, and handling unmanaged resources, as well as
configuring deny settings and specifying ARM or Bicep templates. This GitHub
Action streamlines the process of managing Azure infrastructure, enabling
efficient and automated deployments.

## Getting Started

```bash
git add .
git commit -m "My first action is ready!"
```
```yaml
- name: Login
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

- name: Deployment
uses: ljtill/azure-deployment-stacks-action@v1
with:
name: 'Microsoft.Samples'
description: 'Sample description for the Deployment Stack'
location: uksouth
scope: subscription
mode: create
actionOnUnmanage: deleteAll
denySettings: denyWriteAndDelete
subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
templateFile: ./src/main.bicep
parametersFile: ./src/main.bicepparam
wait: true
```

1. Push them to your repository
## Authentication

```bash
git push -u origin releases/v1
```
The default method for authentication involves using the
[`azure/login@v2`](https://github.com/azure/login) action as an initial step.
However, since our codebase relies on the Azure SDK, we utilize the
[DefaultAzureCredential](https://learn.microsoft.com/azure/developer/javascript/sdk/authentication/overview)
chain within the application. This approach enables us to integrate additional
authentication methods like WorkloadIdentityCredential and ManagedIdentity,
which are especially beneficial when executing jobs on Self-Hosted Agents.

1. Create a pull request and get feedback on your action
1. Merge the pull request into the `main` branch
## Modes

Your action is now published! :rocket:
The action supports three modes: `create`, `delete` and `validate`.

For information about versioning your action, see
[Versioning](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)
in the GitHub Actions toolkit.
For `create` mode, it is recommended to use it with `push` triggers. This setup
ensures that whenever changes are pushed to the repository, the action
automatically creates or updates the Azure Deployment Stack accordingly. This is
ideal for continuous integration and deployment workflows, where infrastructure
changes should be applied seamlessly as part of the development process.
Additionally, this will delete or detach resources that are no longer defined
within the Deployment Stack.

## Validate the Action
For `delete` mode, it is recommended to use it with `workflow_dispatch`
triggers. This setup allows for manual initiation of the delete process through
the GitHub Actions interface. Using `workflow_dispatch` triggers provides
greater control and prevents accidental deletions, ensuring that stacks are only
deleted when explicitly requested by an authorized user. This is particularly
useful for maintenance tasks or cleanup operations, where automated deletion
could pose risks.

You can now validate the action by referencing it in a workflow file. For
example, [`ci.yml`](./.github/workflows/ci.yml) demonstrates how to reference an
action in the same repository.
For `validate` mode, it is recommended to use it with `pull_request` triggers.
This ensures that the Azure Deployment Stack is validated whenever a pull
request is created or updated. By integrating validation into the pull request
workflow, you can catch potential issues or misconfigurations before they are
merged into the main branch. This setup is ideal for ensuring the quality and
integrity of infrastructure changes, as it allows for early detection of errors
and provides an opportunity to review and address issues collaboratively. This
approach helps maintain a stable and reliable infrastructure by preventing
problematic changes from being integrated into the production environment.

```yaml
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4

- name: Test Local Action
id: test-action
uses: ./
with:
milliseconds: 1000

- name: Print Output
id: output
run: echo "${{ steps.test-action.outputs.time }}"
```
## Workflows

For example workflow runs, check out the
[Actions tab](https://github.com/actions/typescript-action/actions)! :rocket:
The following samples provide end-to-end implementations of the Azure Deployment
Stamps Action:

## Usage
- [Create](./docs/WORKFLOWS.md#create)
- [Delete](./docs/WORKFLOWS.md#delete)
- [Validate](./docs/WORKFLOWS.md#validate)

After testing, you can create version tag(s) that developers can use to
reference different stable versions of your action. For more information, see
[Versioning](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)
in the GitHub Actions toolkit.
## Customisation

To include the action in a workflow in another repository, you can use the
`uses` syntax with the `@` symbol to reference a specific branch, tag, or commit
hash.
For a complete list of customisation options, please refer to the
[Parameters](./docs/PARAMETERS.md) document.

```yaml
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4

- name: Test Local Action
id: test-action
uses: actions/typescript-action@v1 # Commit with the `v1` tag
with:
milliseconds: 1000

- name: Print Output
id: output
run: echo "${{ steps.test-action.outputs.time }}"
```
## Documentation

## Publishing a New Release

This project includes a helper script, [`script/release`](./script/release)
designed to streamline the process of tagging and pushing new releases for
GitHub Actions.

GitHub Actions allows users to select a specific version of the action to use,
based on release tags. This script simplifies this process by performing the
following steps:

1. **Retrieving the latest release tag:** The script starts by fetching the most
recent release tag by looking at the local data available in your repository.
1. **Prompting for a new release tag:** The user is then prompted to enter a new
release tag. To assist with this, the script displays the latest release tag
and provides a regular expression to validate the format of the new tag.
1. **Tagging the new release:** Once a valid new tag is entered, the script tags
the new release.
1. **Pushing the new tag to the remote:** Finally, the script pushes the new tag
to the remote repository. From here, you will need to create a new release in
GitHub and users can easily reference the new tag in their workflows.
- [Deployment Stacks](https://learn.microsoft.com/azure/azure-resource-manager/bicep/deployment-stacks)
Loading
Loading