-
Notifications
You must be signed in to change notification settings - Fork 20
Rewrite deploy action as native Node while preserving v1 behavior #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8fe6c1e
Rewrite action as native Node implementation
githubsaturn 52e863c
Keep v1 documentation formatting focused
githubsaturn d3a2bc7
Introduce simplified v2 deployment UX
githubsaturn aff3c01
Address native action review findings
githubsaturn de226c9
Merge updated native action base and address v2 review findings
githubsaturn 040c20d
Address automated review feedback
githubsaturn 7f06adb
Carry automated review fixes into v2
githubsaturn 31015bd
Merge pull request #20 from caprover/v2-native-action
githubsaturn ebc009a
Add one-click Node action releases
githubsaturn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,53 +1,108 @@ | ||
| name: Create Release | ||
| name: Release | ||
|
|
||
| on: | ||
| push: | ||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| version: | ||
| description: Release version without the leading v, for example 2.0.0 | ||
| required: true | ||
| type: string | ||
|
|
||
| # Publish `master` as Docker `latest` image. | ||
| branches: | ||
| - main | ||
| permissions: | ||
| contents: read | ||
|
|
||
| # Publish `v1.2.3` tags as releases. | ||
| tags: | ||
| - v* | ||
| concurrency: | ||
| group: release | ||
| cancel-in-progress: false | ||
|
|
||
| # Create a button to trigger the workflow manually. | ||
| workflow_dispatch: | ||
| jobs: | ||
| verify: | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| tag: ${{ steps.version.outputs.tag }} | ||
| major_tag: ${{ steps.version.outputs.major_tag }} | ||
| steps: | ||
| - name: Require the main branch | ||
| if: github.ref != 'refs/heads/main' | ||
| run: | | ||
| echo '::error::Releases must be created from the main branch.' | ||
| exit 1 | ||
|
|
||
| env: | ||
| # the target name of the image. | ||
| IMAGE_NAME: deploy-from-github | ||
| - uses: actions/checkout@v6 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| jobs: | ||
| # Push image to GitHub Packages Container Registry. | ||
| push: | ||
| - uses: actions/setup-node@v6 | ||
| with: | ||
| node-version: 24 | ||
| cache: npm | ||
|
|
||
| - name: Validate version | ||
| id: version | ||
| env: | ||
| RELEASE_VERSION: ${{ inputs.version }} | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| if [[ ! "$RELEASE_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | ||
| echo '::error::The version must use the format 2.0.0 without a leading v.' | ||
| exit 1 | ||
| fi | ||
|
|
||
| PACKAGE_VERSION="$(node -p "require('./package.json').version")" | ||
| if [[ "$RELEASE_VERSION" != "$PACKAGE_VERSION" ]]; then | ||
| echo "::error::Requested version $RELEASE_VERSION does not match package.json version $PACKAGE_VERSION." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "tag=v$RELEASE_VERSION" >> "$GITHUB_OUTPUT" | ||
| echo "major_tag=v${RELEASE_VERSION%%.*}" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - run: npm ci | ||
| - run: npm run verify | ||
|
|
||
| release: | ||
| needs: verify | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| packages: write | ||
| contents: read | ||
|
|
||
| contents: write | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
| - name: Create release and update major tag | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| TAG: ${{ needs.verify.outputs.tag }} | ||
| MAJOR_TAG: ${{ needs.verify.outputs.major_tag }} | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| - name: Build image | ||
| run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" | ||
| if gh api "repos/$GITHUB_REPOSITORY/git/ref/tags/$TAG" >/dev/null 2>&1; then | ||
| EXISTING_SHA="$(gh api "repos/$GITHUB_REPOSITORY/commits/$TAG" --jq .sha)" | ||
| if [[ "$EXISTING_SHA" != "$GITHUB_SHA" ]]; then | ||
| echo "::error::Tag $TAG already points to $EXISTING_SHA." | ||
| exit 1 | ||
| fi | ||
| else | ||
| gh api --method POST "repos/$GITHUB_REPOSITORY/git/refs" \ | ||
| -f ref="refs/tags/$TAG" \ | ||
| -f sha="$GITHUB_SHA" >/dev/null | ||
| fi | ||
|
|
||
| - name: Log in to registry | ||
| run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u $ --password-stdin | ||
| if gh api "repos/$GITHUB_REPOSITORY/git/ref/tags/$MAJOR_TAG" >/dev/null 2>&1; then | ||
| gh api --method PATCH "repos/$GITHUB_REPOSITORY/git/refs/tags/$MAJOR_TAG" \ | ||
| -f sha="$GITHUB_SHA" \ | ||
| -F force=true >/dev/null | ||
| else | ||
| gh api --method POST "repos/$GITHUB_REPOSITORY/git/refs" \ | ||
| -f ref="refs/tags/$MAJOR_TAG" \ | ||
| -f sha="$GITHUB_SHA" >/dev/null | ||
| fi | ||
|
|
||
| - name: Push image | ||
| run: | | ||
| IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME | ||
|
|
||
| # Change all uppercase to lowercase | ||
| IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | ||
| # Strip git ref prefix from version | ||
| VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | ||
| # Strip "v" prefix from tag name | ||
| [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') | ||
| # Use Docker `latest` tag convention | ||
| [ "$VERSION" == "main" ] && VERSION=latest | ||
| echo IMAGE_ID=$IMAGE_ID | ||
| echo VERSION=$VERSION | ||
| docker tag $IMAGE_NAME $IMAGE_ID:$VERSION | ||
| docker push $IMAGE_ID:$VERSION | ||
| if gh release view "$TAG" --repo "$GITHUB_REPOSITORY" >/dev/null 2>&1; then | ||
| echo "Release $TAG already exists." | ||
| else | ||
| gh release create "$TAG" \ | ||
| --repo "$GITHUB_REPOSITORY" \ | ||
| --verify-tag \ | ||
| --title "$TAG" \ | ||
| --generate-notes | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| name: Test | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| with: | ||
| persist-credentials: false | ||
| - uses: actions/setup-node@v6 | ||
| with: | ||
| node-version: 24 | ||
| cache: npm | ||
| - run: npm ci | ||
| - run: npm run verify | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| node_modules/ | ||
| coverage/ | ||
| dist-types/ |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.