Skip to content

Commit eda7222

Browse files
authored
MVP (#4)
* chore: define action metadata * feat(utils): add getConfig method * feat(utils): add findPackageVersionByTag method * chore: remove uneed tests * fix(utils): tests * fix(workflow): change token to PAT * chore(workflow): naming * feat: add integration test of action * fix workflow * add logs * build * add logs * try to migrate to github token * perms * perms * fix * migrate to gcr token in action * renaming * remove uneed file * docs: update readme
1 parent aacbf76 commit eda7222

17 files changed

Lines changed: 6833 additions & 221 deletions

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**

.github/workflows/ci.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: "CI"
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
- "releases/*"
9+
10+
11+
12+
jobs:
13+
test-code:
14+
name: Test Code
15+
env:
16+
INTEGRATION_TEST_TOKEN: ${{ secrets.GCR_TOKEN }}
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v2
20+
- run: npm ci
21+
- run: npm test
22+
23+
test-actions:
24+
name: Test Action
25+
runs-on: ubuntu-latest
26+
needs: [test-code]
27+
permissions:
28+
packages: write
29+
contents: read
30+
steps:
31+
- uses: actions/checkout@v2
32+
33+
- name: Login to GitHub Container Registry
34+
uses: docker/login-action@v1
35+
with:
36+
registry: ghcr.io
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Build and Push Dummy Image
41+
uses: docker/build-push-action@v2
42+
with:
43+
context: .
44+
push: true
45+
file: Dockerfile.dummy
46+
tags: |
47+
ghcr.io/${{ github.repository_owner }}/ghcr-delete-image-dummy:${{ github.run_number }}
48+
49+
- uses: ./
50+
with:
51+
owner: bots-house
52+
name: ghcr-delete-image-dummy
53+
token: ${{ secrets.GCR_TOKEN }}
54+
tag: ${{ github.run_number }}

.github/workflows/test.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

CODEOWNERS

Lines changed: 0 additions & 1 deletion
This file was deleted.

Dockerfile.dummy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM scratch
2+
3+
LABEL org.opencontainers.image.source="https://github.com/bots-house/ghcr-delete-image"

README.md

Lines changed: 4 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,6 @@
1-
# Create a JavaScript Action
1+
# ghcr-delete-image
22

3-
<p align="center">
4-
<a href="https://github.com/actions/javascript-action/actions"><img alt="javscript-action status" src="https://github.com/actions/javascript-action/workflows/units-test/badge.svg"></a>
5-
</p>
3+
[![CI](https://github.com/bots-house/ghcr-delete-image-action/actions/workflows/ci.yml/badge.svg)](https://github.com/bots-house/ghcr-delete-image-action/actions/workflows/ci.yml)
64

7-
Use this template to bootstrap the creation of a JavaScript action.:rocket:
8-
9-
This template includes tests, linting, a validation workflow, publishing, and versioning guidance.
10-
11-
If you are new, there's also a simpler introduction. See the [Hello World JavaScript Action](https://github.com/actions/hello-world-javascript-action)
12-
13-
## Create an action from this template
14-
15-
Click the `Use this Template` and provide the new repo details for your action
16-
17-
## Code in Main
18-
19-
Install the dependencies
20-
21-
```bash
22-
npm install
23-
```
24-
25-
Run the tests :heavy_check_mark:
26-
27-
```bash
28-
$ npm test
29-
30-
PASS ./index.test.js
31-
✓ throws invalid number (3ms)
32-
wait 500 ms (504ms)
33-
test runs (95ms)
34-
...
35-
```
36-
37-
## Change action.yml
38-
39-
The action.yml defines the inputs and output for your action.
40-
41-
Update the action.yml with your name, description, inputs and outputs for your action.
42-
43-
See the [documentation](https://help.github.com/en/articles/metadata-syntax-for-github-actions)
44-
45-
## Change the Code
46-
47-
Most toolkit and CI/CD operations involve async operations so the action is run in an async function.
48-
49-
```javascript
50-
const core = require('@actions/core');
51-
...
52-
53-
async function run() {
54-
try {
55-
...
56-
}
57-
catch (error) {
58-
core.setFailed(error.message);
59-
}
60-
}
61-
62-
run()
63-
```
64-
65-
See the [toolkit documentation](https://github.com/actions/toolkit/blob/master/README.md#packages) for the various packages.
66-
67-
## Package for distribution
68-
69-
GitHub Actions will run the entry point from the action.yml. Packaging assembles the code into one file that can be checked in to Git, enabling fast and reliable execution and preventing the need to check in node_modules.
70-
71-
Actions are run from GitHub repos. Packaging the action will create a packaged action in the dist folder.
72-
73-
Run prepare
74-
75-
```bash
76-
npm run prepare
77-
```
78-
79-
Since the packaged index.js is run from the dist folder.
80-
81-
```bash
82-
git add dist
83-
```
84-
85-
## Create a release branch
86-
87-
Users shouldn't consume the action from master since that would be latest code and actions can break compatibility between major versions.
88-
89-
Checkin to the v1 release branch
90-
91-
```bash
92-
git checkout -b v1
93-
git commit -a -m "v1 release"
94-
```
95-
96-
```bash
97-
git push origin v1
98-
```
99-
100-
Note: We recommend using the `--license` option for ncc, which will create a license file for all of the production node modules used in your project.
101-
102-
Your action is now published! :rocket:
103-
104-
See the [versioning documentation](https://github.com/actions/toolkit/blob/master/docs/action-versioning.md)
105-
106-
## Usage
107-
108-
You can now consume the action by referencing the v1 branch
109-
110-
```yaml
111-
uses: actions/javascript-action@v1
112-
with:
113-
milliseconds: 1000
114-
```
115-
116-
See the [actions tab](https://github.com/actions/javascript-action/actions) for runs of this action! :rocket:
5+
Delete image from [Github Container Registry](https://github.com/features/packages) by tag.
6+
Useful for cleanup of pull request scoped images.

action.yml

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
1-
name: 'Wait'
2-
description: 'Wait a designated number of milliseconds'
1+
name: 'Delete GitHub Container Registry Image'
2+
description: 'Delete GitHub Container Registry Image by specified tag'
3+
author: bots-house
4+
5+
branding:
6+
icon: delete
7+
color: blue
8+
39
inputs:
4-
milliseconds: # id of input
5-
description: 'number of milliseconds to wait'
10+
owner:
11+
description: >
12+
Owner of the package (user or organization)
613
required: true
7-
default: '1000'
8-
outputs:
9-
time: # output will be available to future steps
10-
description: 'The message to output'
14+
15+
name:
16+
description: >
17+
Name of the package containing the version to delete.
18+
required: true
19+
20+
token:
21+
description: >
22+
Token with the necessary scopes to delete package versions.
23+
required: true
24+
25+
tag:
26+
description: >
27+
Tag to delete
28+
required: true
29+
30+
1131
runs:
1232
using: 'node12'
1333
main: 'dist/index.js'

0 commit comments

Comments
 (0)