-
Notifications
You must be signed in to change notification settings - Fork 44
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
dev: debug container workflow #413
Merged
da2ce7
merged 1 commit into
torrust:develop
from
da2ce7:20230911_debug_container_workflow
Sep 11, 2023
Merged
dev: debug container workflow #413
da2ce7
merged 1 commit into
torrust:develop
from
da2ce7:20230911_debug_container_workflow
Sep 11, 2023
Conversation
This file contains 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
da2ce7
force-pushed
the
20230911_debug_container_workflow
branch
from
September 11, 2023 10:58
86d90ec
to
7a18092
Compare
da2ce7
force-pushed
the
20230911_debug_container_workflow
branch
from
September 11, 2023 11:00
7a18092
to
3d33c18
Compare
da2ce7
force-pushed
the
20230911_debug_container_workflow
branch
from
September 11, 2023 11:03
3d33c18
to
0541c6b
Compare
da2ce7
force-pushed
the
20230911_debug_container_workflow
branch
from
September 11, 2023 11:06
0541c6b
to
c7cb3f0
Compare
da2ce7
force-pushed
the
20230911_debug_container_workflow
branch
from
September 11, 2023 11:09
c7cb3f0
to
da476a7
Compare
Hey @da2ce7 this is refactored version extracting functions (not tested): context:
name: Context
runs-on: ubuntu-latest
outputs:
continue: ${{ steps.check.outputs.continue }}
type: ${{ steps.check.outputs.type }}
version: ${{ steps.check.outputs.version }}
steps:
- id: check
name: Check Context
run: |
REPO="${{ github.repository }}"
EVENT="${{ github.event_name }}"
REF="${{ github.ref }}"
function handleMainBranch() {
echo "type=development" >> $GITHUB_OUTPUT
echo "continue=true" >> $GITHUB_OUTPUT
echo "On \`main\` Branch, Type: \`development\`"
}
function handleDevelopBranch() {
echo "type=development" >> $GITHUB_OUTPUT
echo "continue=true" >> $GITHUB_OUTPUT
echo "On \`develop\` Branch, Type: \`development\`"
}
function handleReleaseBranch() {
version=$(echo "$REF" | sed -n -E 's/^(refs\/heads\/releases\/)//p')
echo "version=$version" >> $GITHUB_OUTPUT
echo "type=release" >> $GITHUB_OUTPUT
echo "continue=true" >> $GITHUB_OUTPUT
echo "In \`releases/$version\` Branch, Type: \`release\`"
}
# Verify the repository
if [[ "$REPO" != "torrust/torrust-tracker" ]]; then
echo "On a Forked Repository. Will Not Continue"
exit 0
fi
# Ensure it's a push event
if [[ "$EVENT" != "push" ]]; then
echo "Not a Push Event. Will Not Continue"
exit 0
fi
# Check branch and set context accordingly
case "$REF" in
"refs/heads/main")
handleMainBranch
;;
"refs/heads/develop")
handleDevelopBranch
;;
refs/heads/releases/*)
if [[ "$REF" =~ ^(refs\/heads\/releases\/)(v)(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$ ]]; then
handleReleaseBranch
else
echo "Not Correct Branch. Will Not Continue"
fi
;;
*)
echo "Not Correct Branch. Will Not Continue"
;;
esac
On the other hand, I'm always tempted not to use bash but TypeScript, so we can even add tests for the workflow code. // releaseLogic.ts
interface GithubContext {
repository: string;
eventName: string;
ref: string;
}
function main(context: GithubContext) {
// Your TypeScript logic here
// ...
// To set GitHub Action outputs, use the `setOutput` function:
// setOutput('continue', 'true');
// ...
}
function setOutput(name: string, value: string) {
console.log(`::set-output name=${name}::${value}`);
}
// Get context from environment variables or however you wish to pass them
const githubContext: GithubContext = {
repository: process.env.GITHUB_REPOSITORY || '',
eventName: process.env.GITHUB_EVENT_NAME || '',
ref: process.env.GITHUB_REF || ''
};
main(githubContext); context:
name: Context
runs-on: ubuntu-latest
outputs:
continue: ${{ steps.check.outputs.continue }}
type: ${{ steps.check.outputs.type }}
version: ${{ steps.check.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '14' # or whichever version you prefer
- name: Install dependencies
run: npm install typescript
- name: Transpile TypeScript
run: npx tsc releaseLogic.ts --target ES6 --module commonjs
- name: Run Workflow Logic
id: check
run: node workflowLogic.js
env:
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_EVENT_NAME: ${{ github.event_name }}
GITHUB_REF: ${{ github.ref }} And maybe even in Rust. But maybe for the time being with a couple of comments is OK because the code is not too big. |
da2ce7
force-pushed
the
20230911_debug_container_workflow
branch
from
September 11, 2023 12:50
e1274e2
to
da476a7
Compare
ACK da476a7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.