Skip to content
Open
15 changes: 0 additions & 15 deletions .github/workflows/custom-action.yml

This file was deleted.

152 changes: 152 additions & 0 deletions .github/workflows/publish-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
name: Publish Package

on:
release:
types: [created]
workflow_dispatch:
inputs:
version:
description: 'Package version'
required: true
default: '1.0.0'

jobs:
# Publishing a Node.js Package
publish-npm:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '18.x'
registry-url: 'https://npm.pkg.github.com'
scope: '@octocat'

- name: Install dependencies
run: npm ci

- name: Build
run: npm run build --if-present

- name: Publish to GitHub Packages
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Publishing a Python Package
publish-python:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine

- name: Build package
run: python -m build

- name: Publish to GitHub Packages
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
TWINE_REPOSITORY_URL: https://github-package-registry.com/octocat/python-package
run: twine upload dist/*

# Publishing a Docker Image
publish-docker:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4

- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}}
type=sha,format=long

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

# Publishing a Java Package
publish-java:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4

- name: Set up JDK
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: 'maven'
server-id: github

- name: Build with Maven
run: mvn -B package

- name: Publish to GitHub Packages
run: mvn --batch-mode deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Publishing a .NET NuGet Package
publish-nuget:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: '7.0.x'
source-url: https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json
env:
NUGET_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build
run: dotnet build --configuration Release

- name: Create package
run: dotnet pack --configuration Release

- name: Publish package
run: dotnet nuget push "**/*.nupkg" --source "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"githubPullRequests.ignoredPullRequestBranches": [
"main"
]
}
126 changes: 126 additions & 0 deletions github-actions/templates/context-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
name: GitHub Context Examples

on:
push:
branches: [ main ]
pull_request:
types: [opened, synchronize, reopened]
issues:
types: [opened, edited, labeled]
workflow_dispatch:
inputs:
environment:
description: 'Environment to deploy to'
required: true
default: 'staging'
type: choice
options:
- staging
- production

jobs:
explore-github-context:
runs-on: ubuntu-latest
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: echo "$GITHUB_CONTEXT"

- name: Repository Information
run: |
echo "Repository: ${{ github.repository }}"
echo "Repository Owner: ${{ github.repository_owner }}"
echo "Repository Name: ${{ github.event.repository.name }}"
echo "Default Branch: ${{ github.event.repository.default_branch }}"
echo "Is Private: ${{ github.event.repository.private }}"

- name: Event Information
run: |
echo "Event Name: ${{ github.event_name }}"
echo "Event Type: ${{ github.event.action }}"
echo "Workflow: ${{ github.workflow }}"
echo "Run ID: ${{ github.run_id }}"
echo "Run Number: ${{ github.run_number }}"

- name: Actor Information
run: |
echo "Actor: ${{ github.actor }}"
echo "Actor ID: ${{ github.actor_id }}"
echo "Triggering Actor: ${{ github.triggering_actor }}"

- name: Git Information
run: |
echo "Ref: ${{ github.ref }}"
echo "SHA: ${{ github.sha }}"
echo "Ref Type: ${{ github.ref_type }}"
echo "Ref Name: ${{ github.ref_name }}"
echo "Base Ref: ${{ github.base_ref }}"
echo "Head Ref: ${{ github.head_ref }}"

- name: Environment Information
run: |
echo "Workspace: ${{ github.workspace }}"
echo "Action: ${{ github.action }}"
echo "Action Path: ${{ github.action_path }}"
echo "Server URL: ${{ github.server_url }}"
echo "API URL: ${{ github.api_url }}"
echo "Graphql URL: ${{ github.graphql_url }}"

- name: Pull Request Specific Info
if: github.event_name == 'pull_request'
run: |
echo "PR Number: ${{ github.event.number }}"
echo "PR Title: ${{ github.event.pull_request.title }}"
echo "PR Body: ${{ github.event.pull_request.body }}"
echo "PR State: ${{ github.event.pull_request.state }}"
echo "PR Base Branch: ${{ github.event.pull_request.base.ref }}"
echo "PR Head Branch: ${{ github.event.pull_request.head.ref }}"
echo "PR User: ${{ github.event.pull_request.user.login }}"

- name: Issue Specific Info
if: github.event_name == 'issues'
run: |
echo "Issue Number: ${{ github.event.issue.number }}"
echo "Issue Title: ${{ github.event.issue.title }}"
echo "Issue Body: ${{ github.event.issue.body }}"
echo "Issue State: ${{ github.event.issue.state }}"
echo "Issue Creator: ${{ github.event.issue.user.login }}"
echo "Issue Labels: ${{ join(github.event.issue.labels.*.name, ', ') }}"

- name: Workflow Dispatch Info
if: github.event_name == 'workflow_dispatch'
run: |
echo "Selected Environment: ${{ github.event.inputs.environment }}"

- name: Runner Information
run: |
echo "Runner OS: ${{ runner.os }}"
echo "Runner Name: ${{ runner.name }}"
echo "Runner Temp: ${{ runner.temp }}"
echo "Runner Tool Cache: ${{ runner.tool_cache }}"

- name: Job Information
run: |
echo "Job ID: ${{ github.job }}"
echo "Job Container ID: ${{ job.container.id }}"
echo "Job Services: ${{ toJSON(job.services) }}"

- name: Demonstration of Conditions
run: |
echo "This step runs on all events"
if: always()

- name: Push Event Specific
if: github.event_name == 'push'
run: |
echo "Commits in Push:"
echo "${{ toJSON(github.event.commits) }}"
echo "Pusher Name: ${{ github.event.pusher.name }}"
echo "Pusher Email: ${{ github.event.pusher.email }}"

- name: Security Related Context
run: |
echo "Running in GHES: ${{ github.event.repository.is_enterprise }}"
echo "Repository Topics: ${{ toJSON(github.event.repository.topics) }}"
echo "Repository Visibility: ${{ github.event.repository.visibility }}"
29 changes: 22 additions & 7 deletions github-actions/templates/expression-functions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,39 @@ jobs:
- name: Check if string contains substring
if: contains('Hello world', 'llo')
run: echo "The string contains the substring."

- name: Check if string starts with
if: startsWith('Hello world', 'He')
run: echo "The string starts with 'He'."

- name: Check if string ends with
if: endsWith('Hello world', 'ld')
run: echo "The string ends with 'ld'."

- name: Format and echo string
run: echo ${{ format('Hello {0} {1} {2}', 'Mona', 'the', 'Octocat') }}
run: echo "${{ format('Hello {0} {1} {2}', 'Mona', 'the', 'Octocat') }}"

- name: Join issue labels
if: github.event_name == 'issues'
run: echo "Issue labels: ${{ join(github.event.issue.labels.*.name, ', ') }}"
run: |
echo "Issue labels: ${{ join(github.event.issue.labels.*.name, ', ') }}"

- name: Convert job context to JSON
run: echo "Job context in JSON: ${{ toJSON(github.job) }}"
run: |
echo "Job context in JSON: ${{ toJSON(github.job) }}"

- name: Parse JSON string
run: echo "Parsed JSON: ${{ fromJSON('{"hello":"world"}').hello }}"
run: |
echo "Parsed JSON: ${{ fromJSON('{"hello":"world"}').hello }}"

- name: Hash files
run: echo "Hash of files: ${{ hashFiles('**/package-lock.json', '**/Gemfile.lock') }}
run: |
echo "Hash of files: ${{ hashFiles('**/package-lock.json', '**/Gemfile.lock') }}"

- name: The job has succeeded
if: ${{ success() }}
if: success()
run: echo "Job succeeded"

- name: The job has failed
if: ${{ failure() }}
if: failure()
run: echo "Job failed"
Loading