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

Mirror the individual monorepo packages so that this can be published in the GitHub Actions Marketplace #8

Merged
merged 3 commits into from
Oct 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,11 @@ jobs:
packages/automatic-releases/dist/index.js
packages/keybase-notifications/dist/index.js
packages/keybase-notifications/dist/keybase

# marvinpinto/action-keybase-notifications
# marvinpinto/action-automatic-releases
- name: "Automatically mirror release artifacts"
env:
GITHUB_SUPER_TOKEN: ${{ secrets.GITHUB_SUPER_TOKEN }}
run: |
./scripts/mirror-actions.sh "$AUTOMATIC_RELEASES_TAG"
8 changes: 8 additions & 0 deletions .github/workflows/tagged-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,11 @@ jobs:
packages/automatic-releases/dist/index.js
packages/keybase-notifications/dist/index.js
packages/keybase-notifications/dist/keybase

# marvinpinto/action-keybase-notifications
# marvinpinto/action-automatic-releases
- name: "Automatically mirror release artifacts"
env:
GITHUB_SUPER_TOKEN: ${{ secrets.GITHUB_SUPER_TOKEN }}
run: |
./scripts/mirror-actions.sh "$AUTOMATIC_RELEASES_TAG"
16 changes: 9 additions & 7 deletions packages/automatic-releases/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ This action simplifies the GitHub release process by automatically uploading ass
1. [How to get help](#how-to-get-help)
1. [License](#license)

> **NOTE**: The `marvinpinto/action-automatic-releases` repository is an automatically generated mirror of the [marvinpinto/actions](https://github.com/marvinpinto/actions) monorepo containing this and other actions. Please file issues and pull requests over there.

## Usage Examples

### Automatically generate a pre-release when changes land on master
Expand All @@ -24,7 +26,7 @@ This example workflow will kick in as soon as changes land on `master`. After ru
1. Upload `LICENSE.txt` and any `jar` files as release assets.
1. Mark this release as a `pre-release`.

You can see an example of the end result of this workflow [on this repository](../../../../releases/tag/latest).
You can see a working example of this workflow over at [marvinpinto/actions](https://github.com/marvinpinto/actions/releases/tag/latest).

```yaml
---
Expand All @@ -46,7 +48,7 @@ jobs:
run: |
echo "done!"

- uses: "marvinpinto/actions/packages/automatic-releases@latest"
- uses: "marvinpinto/actions-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
automatic_release_tag: "latest"
Expand All @@ -65,7 +67,7 @@ Similar to the previous example, this workflow will kick in as soon as new tags
1. Generate a new release and associate it with this tag.
1. Upload `LICENSE.txt` and any `jar` files as release assets.

As before, you can see an example of the end result [here](../../../../releases/latest).
Once again there's an example of this over at [marvinpinto/actions](https://github.com/marvinpinto/actions/releases/latest).

```yaml
---
Expand All @@ -87,7 +89,7 @@ jobs:
run: |
echo "done!"

- uses: "marvinpinto/actions/packages/automatic-releases@latest"
- uses: "marvinpinto/actions-automatic-releases@latest"
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
prerelease: false
Expand Down Expand Up @@ -118,15 +120,15 @@ The GitHub Actions framework allows you to trigger this (and other) actions on _

## Versioning

Every commit that lands on master for this project triggers an automatic build as well as a tagged release called `latest`. If you don't wish to live on the bleeding edge you may use a stable release instead. See [releases](../../../../releases) for the available versions.
Every commit that lands on master for this project triggers an automatic build as well as a tagged release called `latest`. If you don't wish to live on the bleeding edge you may use a stable release instead. See [releases](../../releases/latest) for the available versions.

```yaml
- uses: "marvinpinto/actions/packages/automatic-releases@<VERSION>"
- uses: "marvinpinto/actions-automatic-releases@<VERSION>"
```

## How to get help

The main [README](../../README.md) for this project has a bunch of information related to debugging & submitting issues. If you're still stuck, try and get a hold of me on [keybase](https://keybase.io/marvinpinto) and I'll do my best.
The main [README](https://github.com/marvinpinto/actions/blob/master/README.md) for this project has a bunch of information related to debugging & submitting issues. If you're still stuck, try and get a hold of me on [keybase](https://keybase.io/marvinpinto) and I will do my best to help you out.

## License

Expand Down
13 changes: 13 additions & 0 deletions packages/automatic-releases/__tests__/automaticReleases.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('main handler processing automatic releases', () => {
jest.clearAllMocks();
nock.cleanAll();
nock.enableNetConnect();
delete process.env['AUTOMATIC_RELEASES_TAG'];
});

it('throws an error when "automatic_release_tag" is not supplied', async () => {
Expand Down Expand Up @@ -97,6 +98,9 @@ describe('main handler processing automatic releases', () => {
upload_url: releaseUploadUrl, // eslint-disable-line @typescript-eslint/camelcase
});

// Output env variable should be empty
expect(process.env['AUTOMATIC_RELEASES_TAG']).toBeUndefined();

const inst = require('../src/main');
inst.uploadReleaseArtifacts = jest.fn(() => Promise.resolve());
await inst.main();
Expand All @@ -112,6 +116,9 @@ describe('main handler processing automatic releases', () => {
expect(inst.uploadReleaseArtifacts.mock.calls[0][1]).toBe(releaseUploadUrl);
// Should not attempt to upload any release artifacts, as there are none
expect(inst.uploadReleaseArtifacts.mock.calls[0][2]).toEqual([]);

// Should populate the output env variable
expect(process.env['AUTOMATIC_RELEASES_TAG']).toBe(testInputAutomaticReleaseTag);
});

it('should update an existing release tag', async () => {
Expand Down Expand Up @@ -183,6 +190,9 @@ describe('main handler processing automatic releases', () => {
upload_url: releaseUploadUrl, // eslint-disable-line @typescript-eslint/camelcase
});

// Output env variable should be empty
expect(process.env['AUTOMATIC_RELEASES_TAG']).toBeUndefined();

const inst = require('../src/main');
inst.uploadReleaseArtifacts = jest.fn(() => Promise.resolve());
await inst.main();
Expand All @@ -199,5 +209,8 @@ describe('main handler processing automatic releases', () => {
expect(inst.uploadReleaseArtifacts).toHaveBeenCalledTimes(1);
expect(inst.uploadReleaseArtifacts.mock.calls[0][1]).toBe(releaseUploadUrl);
expect(inst.uploadReleaseArtifacts.mock.calls[0][2]).toEqual(['file1.txt', 'file2.txt', '*.jar']);

// Should populate the output env variable
expect(process.env['AUTOMATIC_RELEASES_TAG']).toBe(testInputAutomaticReleaseTag);
});
});
7 changes: 7 additions & 0 deletions packages/automatic-releases/__tests__/taggedReleases.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('main handler processing tagged releases', () => {
jest.clearAllMocks();
nock.cleanAll();
nock.enableNetConnect();
delete process.env['AUTOMATIC_RELEASES_TAG'];
});

it('throws an error if the github event tag does not conform to semantic versioning', async () => {
Expand Down Expand Up @@ -107,6 +108,9 @@ describe('main handler processing tagged releases', () => {
upload_url: releaseUploadUrl,
});

// Output env variable should be empty
expect(process.env['AUTOMATIC_RELEASES_TAG']).toBeUndefined();

const inst = require('../src/main');
inst.uploadReleaseArtifacts = jest.fn(() => Promise.resolve());
await inst.main();
Expand All @@ -119,5 +123,8 @@ describe('main handler processing tagged releases', () => {
expect(inst.uploadReleaseArtifacts).toHaveBeenCalledTimes(1);
expect(inst.uploadReleaseArtifacts.mock.calls[0][1]).toBe(releaseUploadUrl);
expect(inst.uploadReleaseArtifacts.mock.calls[0][2]).toEqual(['file1.txt', 'file2.txt', '*.jar']);

// Should populate the output env variable
expect(process.env['AUTOMATIC_RELEASES_TAG']).toBe('v0.0.1');
});
});
3 changes: 3 additions & 0 deletions packages/automatic-releases/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ export const main = async () => {
});

await uploadReleaseArtifacts(client, releaseUploadUrl, args.files);

core.debug(`Exporting environment variable AUTOMATIC_RELEASES_TAG with value ${releaseTag}`);
core.exportVariable('AUTOMATIC_RELEASES_TAG', releaseTag);
} catch (error) {
core.setFailed(error.message);
throw error;
Expand Down
14 changes: 8 additions & 6 deletions packages/keybase-notifications/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ This action allows you to post messages to [Keybase Chat](https://keybase.io/blo
1. [How to get help](#how-to-get-help)
1. [License](#license)

> **NOTE**: The `marvinpinto/action-keybase-notifications` repository is an automatically generated mirror of the [marvinpinto/actions](https://github.com/marvinpinto/actions) monorepo containing this and other actions. Please file issues and pull requests over there.

## Using the Action

You will need a Keybase paperkey and its corresponding username. It is probably a good idea to create a dedicated Keybase account for this purpose, or at the very least generate a dedicated paperkey on your existing account. This makes it easier to revoke if needed.
Expand All @@ -35,7 +37,7 @@ jobs:
keybase:
runs-on: "ubuntu-latest"
steps:
- uses: "marvinpinto/actions/packages/keybase-notifications@latest"
- uses: "marvinpinto/actions-keybase-notifications@latest"
with:
keybase_username: "${{ secrets.KeybaseUsername }}"
keybase_paper_key: "${{ secrets.KeybasePaperKey }}" # "fancy regular ..."
Expand All @@ -50,7 +52,7 @@ jobs:
keybase:
runs-on: "ubuntu-latest"
steps:
- uses: "marvinpinto/actions/packages/keybase-notifications@latest"
- uses: "marvinpinto/actions-keybase-notifications@latest"
with:
keybase_username: "${{ secrets.KeybaseUsername }}"
keybase_paper_key: "${{ secrets.KeybasePaperKey }}" # "fancy regular ..."
Expand All @@ -64,7 +66,7 @@ jobs:
keybase:
runs-on: "ubuntu-latest"
steps:
- uses: "marvinpinto/actions/packages/keybase-notifications@latest"
- uses: "marvinpinto/actions-keybase-notifications@latest"
with:
message: "Hey there, world!"
keybase_username: "${{ secrets.KeybaseUsername }}"
Expand Down Expand Up @@ -134,15 +136,15 @@ Read through the [GitHub documentation](https://help.github.com/en/articles/work

## Versioning

Every commit that lands on master for this project triggers an automatic build as well as a tagged release called `latest`. If you don't wish to live on the bleeding edge you may use a stable release instead. See [releases](https://github.com/marvinpinto/actions/releases) for the available versions.
Every commit that lands on master for this project triggers an automatic build as well as a tagged release called `latest`. If you don't wish to live on the bleeding edge you may use a stable release instead. See [releases](../../releases/latest) for the available versions.

```yaml
- uses: "marvinpinto/actions/packages/keybase-notifications@<VERSION>"
- uses: "marvinpinto/actions-keybase-notifications@<VERSION>"
```

## How to get help

The main [README](../../README.md) for this project has a bunch of information related to debugging & submitting issues. If you're still stuck, try and get a hold of me on [keybase](https://keybase.io/marvinpinto) and I'll do my best.
The main [README](https://github.com/marvinpinto/actions/blob/master/README.md) for this project has a bunch of information related to debugging & submitting issues. If you're still stuck, try and get a hold of me on [keybase](https://keybase.io/marvinpinto) and I will do my best to help you out.

## License

Expand Down
101 changes: 101 additions & 0 deletions scripts/mirror-actions.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#!/usr/bin/env bash

set -e

if [[ $# -ne 1 ]]; then
echo "This needs a release tag. e.g. $0 v0.0.1"
exit 1
fi

if [[ -z "$GITHUB_SUPER_TOKEN" ]]; then
echo "This script needs a GitHub personal access token."
exit 1
fi

ACTION_KEYBASE_NOTIFICATIONS_REPO="action-keybase-notifications"
ACTION_AUTOMATIC_RELEASES_REPO="action-automatic-releases"
TAG=$1
GITHUB_LOGIN="marvinpinto"
RELEASE_BODY="Details available at [marvinpinto/actions@${TAG}](https://github.com/marvinpinto/actions/releases/tag/${TAG})."

PRERELEASE="false"
if [[ "$TAG" == "latest" ]]; then
PRERELEASE="true"
fi

if [[ "$GITHUB_REPOSITORY" != "marvinpinto/actions" ]]; then
echo "This mirror script is only meant to be run from marvinpinto/actions, not ${GITHUB_REPOSITORY}. Nothing to do here."
exit 0
fi

create_tagged_release() {
REPO=$1
pushd /tmp/${REPO}/

# Set the local git identity
git config user.email "${GITHUB_LOGIN}@users.noreply.github.com"
git config user.name "$GITHUB_LOGIN"

# Obtain the release ID for the previous release of $TAG (if present)
local previous_release_id=$(curl --user ${GITHUB_LOGIN}:${GITHUB_SUPER_TOKEN} --request GET --silent https://api.github.com/repos/${GITHUB_LOGIN}/${REPO}/releases/tags/${TAG} | jq '.id')

# Delete the previous release (if present)
if [[ -n "$previous_release_id" ]]; then
echo "Deleting previous release: ${previous_release_id}"
curl \
--user ${GITHUB_LOGIN}:${GITHUB_SUPER_TOKEN} \
--request DELETE \
--silent \
https://api.github.com/repos/${GITHUB_LOGIN}/${REPO}/releases/${previous_release_id}
fi

# Delete previous identical tags, if present
git tag -d $TAG || true
git push origin :$TAG || true

# Add all the changed files and push the changes upstream
git add -f .
git commit -m "Update release files for tag: ${TAG}" || true
git push -f origin master:master
git tag $TAG
git push origin $TAG

# Generate a skeleton release on GitHub
curl \
--user ${GITHUB_LOGIN}:${GITHUB_SUPER_TOKEN} \
--request POST \
--silent \
--data @- \
https://api.github.com/repos/${GITHUB_LOGIN}/${REPO}/releases <<END
{
"tag_name": "$TAG",
"name": "Auto-generated release for tag $TAG",
"body": "$RELEASE_BODY",
"draft": false,
"prerelease": $PRERELEASE
}
END
popd
}

# Mirroring Keybase Notifications
rm -rf "/tmp/${ACTION_KEYBASE_NOTIFICATIONS_REPO}"
git clone "https://marvinpinto:${GITHUB_SUPER_TOKEN}@github.com/marvinpinto/${ACTION_KEYBASE_NOTIFICATIONS_REPO}.git" /tmp/${ACTION_KEYBASE_NOTIFICATIONS_REPO}
mkdir -p /tmp/${ACTION_KEYBASE_NOTIFICATIONS_REPO}/dist
cp packages/keybase-notifications/dist/index.js /tmp/${ACTION_KEYBASE_NOTIFICATIONS_REPO}/dist/
cp packages/keybase-notifications/dist/keybase /tmp/${ACTION_KEYBASE_NOTIFICATIONS_REPO}/dist/
cp -R packages/keybase-notifications/images /tmp/${ACTION_KEYBASE_NOTIFICATIONS_REPO}/
cp packages/keybase-notifications/README.md /tmp/${ACTION_KEYBASE_NOTIFICATIONS_REPO}/
cp packages/keybase-notifications/action.yml /tmp/${ACTION_KEYBASE_NOTIFICATIONS_REPO}/
cp LICENSE /tmp/${ACTION_KEYBASE_NOTIFICATIONS_REPO}/
create_tagged_release "$ACTION_KEYBASE_NOTIFICATIONS_REPO"

# Mirroring Automatic Releases
rm -rf "/tmp/${ACTION_AUTOMATIC_RELEASES_REPO}"
git clone "https://marvinpinto:${GITHUB_SUPER_TOKEN}@github.com/marvinpinto/${ACTION_AUTOMATIC_RELEASES_REPO}.git" /tmp/${ACTION_AUTOMATIC_RELEASES_REPO}
mkdir -p /tmp/${ACTION_AUTOMATIC_RELEASES_REPO}/dist
cp packages/automatic-releases/dist/index.js /tmp/${ACTION_AUTOMATIC_RELEASES_REPO}/dist/
cp packages/automatic-releases/README.md /tmp/${ACTION_AUTOMATIC_RELEASES_REPO}/
cp packages/automatic-releases/action.yml /tmp/${ACTION_AUTOMATIC_RELEASES_REPO}/
cp LICENSE /tmp/${ACTION_AUTOMATIC_RELEASES_REPO}/
create_tagged_release "$ACTION_AUTOMATIC_RELEASES_REPO"
22 changes: 0 additions & 22 deletions scripts/release.sh

This file was deleted.